1 /* GabeditContoursPlot.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 #define GETTEXT_PACKAGE "gabedit"
21 #include <stdlib.h>
22 #include <ctype.h>
23 #include <math.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <gdk/gdk.h>
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtk.h>
29 #include <glib/gi18n.h>
30 #include <cairo-pdf.h>
31 #include <cairo-ps.h>
32 #include <cairo-svg.h>
33 
34 #include "GabeditContoursPlot.h"
35 #include "Interpolation.h"
36 
37 #define ContoursPLOT_DEFAULT_SIZE 300
38 #define BSIZE 1024
39 #define SCALE(i) (i / 65535.)
40 #define SCALE2(i) (i * 65535.)
41 
42 typedef enum
43 {
44   JDX_TYPE_ContoursDATA,
45   JDX_TYPE_ContoursPOINTS,
46   JDX_TYPE_ContoursTABLE,
47   JDX_TYPE_UNKNOWN
48 } JDXType;
49 
50 /****************************************************************************************/
51 static void gabedit_contoursplot_cairo_string(cairo_t* cr, GtkWidget *widget, GdkGC* gc, gint x, gint y, G_CONST_RETURN gchar* str, gboolean centerX, gboolean centerY, gdouble angle);
52 static void gabedit_contoursplot_cairo_line(cairo_t* cr, GtkWidget *widget, GdkGC* gc, gdouble x1,gdouble y1,gdouble x2,gdouble y2);
53 static void gabedit_contoursplot_cairo_lines(cairo_t *cr,  GtkWidget* widget, GdkGC* gc, GdkPoint* points, gint size);
54 static void gabedit_contoursplot_cairo_rectangle(cairo_t* cr, GtkWidget *widget, GdkGC* gc, gboolean fill, gdouble x1,gdouble y1,gdouble w,gdouble h);
55 /* static void gabedit_contoursplot_cairo_cercle(cairo_t* cr, GtkWidget *widget, GdkGC* gc, gint xc,gint yc,gint rayon);*/
56 
57 static void contoursplot_cairo_string(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gint x, gint y, G_CONST_RETURN gchar* str, gboolean centerX, gboolean centerY, gdouble angle);
58 static void contoursplot_cairo_image(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget *widget, gint x, gint y, gint w, gint h, cairo_surface_t *image);
59 static void contoursplot_cairo_line(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gdouble x1,gdouble y1,gdouble x2,gdouble y2);
60 static void contoursplot_cairo_lines(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, GdkPoint* points, gint size);
61 static void contoursplot_cairo_rectangle(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gboolean fill, gdouble x1,gdouble y1,gdouble w,gdouble h);
62 /* static void contoursplot_cairo_cercle(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gint xc,gint yc,gint rayon);*/
63 
64 static void gabedit_contoursplot_class_init (GabeditContoursPlotClass    *klass);
65 static void gabedit_contoursplot_init (GabeditContoursPlot         *contoursplot);
66 static void gabedit_contoursplot_destroy (GtkObject        *object);
67 static void gabedit_contoursplot_realize (GtkWidget        *widget);
68 static void gabedit_contoursplot_size_request (GtkWidget      *widget, GtkRequisition *requisition);
69 static void gabedit_contoursplot_size_allocate (GtkWidget     *widget, GtkAllocation *allocation);
70 static gint gabedit_contoursplot_expose (GtkWidget        *widget, GdkEventExpose   *event);
71 static gint gabedit_contoursplot_button_press (GtkWidget   *widget, GdkEventButton   *event);
72 static gint gabedit_contoursplot_button_release (GtkWidget *widget, GdkEventButton   *event);
73 static gint gabedit_contoursplot_motion_notify (GtkWidget  *widget, GdkEventMotion   *event);
74 static gint gabedit_contoursplot_key_press(GtkWidget* widget, GdkEventKey *event);
75 static gint gabedit_contoursplot_key_release(GtkWidget* widget, GdkEventKey *event);
76 static gint gabedit_contoursplot_scroll (GtkWidget        *widget, GdkEventScroll   *event);
77 static void gabedit_contoursplot_style_set (GtkWidget      *widget, GtkStyle       *previous_style);
78 static gint gabedit_contoursplot_grab(GtkWidget* widget, GdkEventCrossing* event);
79 static void gabedit_contoursplot_cairo_layout(cairo_t* cr, gdouble x, gdouble y, PangoLayout *layout, gboolean centerX, gboolean centerY, gdouble angle) ;
80 static void contoursplot_enable_grids (GabeditContoursPlot *contoursplot, GabeditContoursPlotGrid grid, gboolean enable);
81 static void contoursplot_show_colormap (GabeditContoursPlot *contoursplot, gboolean show);
82 static void contoursplot_show_label_contours (GabeditContoursPlot *contoursplot, gboolean show);
83 static void contoursplot_build_position_label_contours (GabeditContoursPlot *contoursplot);
84 static void reset_label_contours(GtkWidget* contoursplot, ContoursPlotData* data);
85 static void contoursplot_dashed_negative_contours (GabeditContoursPlot *contoursplot, gboolean dashed);
86 static void contoursplot_show_left_legends (GabeditContoursPlot *contoursplot, gboolean show);
87 static void contoursplot_show_right_legends (GabeditContoursPlot *contoursplot, gboolean show);
88 static void contoursplot_show_top_legends (GabeditContoursPlot *contoursplot, gboolean show);
89 static void contoursplot_show_bottom_legends (GabeditContoursPlot *contoursplot, gboolean show);
90 static void contoursplot_reflect_x (GabeditContoursPlot *contoursplot, gboolean enable);
91 static void contoursplot_reflect_y (GabeditContoursPlot *contoursplot, gboolean enable);
92 static gint gabedit_contoursplot_draw (GtkWidget *widget);
93 static void set_old_area(GtkWidget *widget, GabeditContoursPlot *contoursplot);
94 
95 /****************************************************************************************/
96 static GtkWidgetClass *parent_class = NULL; /* TO DELETE */
97 /****************************************************************************************/
98 static void contoursplot_calculate_sizes (GabeditContoursPlot *contoursplot);
99 static void value2pixel(GabeditContoursPlot *contoursplot, gdouble xv, gdouble yv, gint *x, gint *y);
100 static void pixel2value(GabeditContoursPlot *contoursplot, gint xp, gint yp, gdouble *x, gdouble *y);
101 static void contoursplot_calculate_legends_sizes(GabeditContoursPlot *contoursplot);
102 static void contoursplot_build_legends(GabeditContoursPlot *contoursplot);
103 static void contoursplot_free_legends(GabeditContoursPlot *contoursplot);
104 static void contoursplot_build_points_contour(GabeditContoursPlot *contoursplot, ContourData *contour);
105 static void contoursplot_calculate_colormap_sizes(GabeditContoursPlot *contoursplot);
106 static void contoursplot_build_colormap_legends(GabeditContoursPlot *contoursplot);
107 static gint get_distance_M_AB(GabeditContoursPlot *contoursplot,gint xM, gint yM, gint ixA, gint iyA, gint ixB, gint iyB);
108 static void saveAsGabeditDlg(GtkWidget* contoursplot);
109 static void readAGabeditDlg(GtkWidget* contoursplot);
110 static void reset_theme(GtkWidget *widget, gint line_width, GdkColor* foreColor, GdkColor* backColor );
111 static void set_theme_publication(GtkWidget *widget);
112 static void set_theme_green_black(GtkWidget *widget);
113 static void set_theme_dialog(GtkWidget* widget);
114 static PangoLayout* get_pango_str(GabeditContoursPlot *contoursplot, G_CONST_RETURN gchar* txt);
115 
116 /****************************************************************************************/
uppercase(gchar * str)117 static void uppercase(gchar *str)
118 {
119   while( *str != '\0')
120   {
121     if (isalpha((gint)*str))
122       if (islower((gint)*str))
123         *str = toupper((gint)*str);
124     str ++;
125   }
126 }
127 /****************************************************************************************/
contoursplot_message(gchar * message)128 static void contoursplot_message(gchar* message)
129 {
130 	GtkWidget* dialog = NULL;
131 	dialog = gtk_message_dialog_new_with_markup (NULL,
132 		           GTK_DIALOG_DESTROY_WITH_PARENT,
133 		           GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
134 			   "%s",
135 			   message);
136        	gtk_dialog_run (GTK_DIALOG (dialog));
137        	gtk_widget_destroy (dialog);
138 }
139 /**********************************************************************************/
calc_arrow_vertexes(gdouble arrow_degrees,gdouble arrow_length,gdouble start_x,gdouble start_y,gdouble end_x,gdouble end_y,gdouble * x1,gdouble * y1,gdouble * x2,gdouble * y2)140 static void calc_arrow_vertexes(
141 		gdouble arrow_degrees,
142 		gdouble arrow_length,
143 		gdouble start_x, gdouble start_y,
144 		gdouble end_x, gdouble end_y,
145 		gdouble* x1, gdouble* y1,
146 		gdouble* x2, gdouble* y2
147 		)
148 {
149 	gdouble angle = atan2 (end_y - start_y, end_x - start_x) + M_PI;
150 	arrow_degrees = arrow_degrees/180.0*M_PI;
151 
152 	*x1 = end_x + arrow_length * cos(angle - arrow_degrees);
153 	*y1 = end_y + arrow_length * sin(angle - arrow_degrees);
154 	*x2 = end_x + arrow_length * cos(angle + arrow_degrees);
155 	*y2 = end_y + arrow_length * sin(angle + arrow_degrees);
156 }
157 /**********************************************************************************/
colormap_free(ColorMap * colorMap)158 static void colormap_free(ColorMap* colorMap)
159 {
160 	if(!colorMap) return;
161 	if(!colorMap->colorValue)
162 	{
163 
164 		colorMap->numberOfColors = 0;
165 		return;
166 	}
167 	g_free(colorMap->colorValue);
168 	colorMap->numberOfColors = 0;
169 }
170 /******************************************************************************************************************************/
colormap_alloc(ColorMap * colorMap,gint numberOfColors)171 static void colormap_alloc(ColorMap* colorMap, gint numberOfColors)
172 {
173 	if(colorMap->colorValue)
174 		colormap_free(colorMap);
175 
176 	if(numberOfColors<1) numberOfColors = 1;
177 	colorMap->numberOfColors = numberOfColors;
178 	colorMap->colorValue = g_malloc(numberOfColors*sizeof(OneColorValue));
179 }
180 /******************************************************************************************************************************/
new_colorMap(gdouble color[],gdouble value)181 static ColorMap new_colorMap(gdouble color[], gdouble value)
182 {
183 	gint c;
184 	ColorMap colorMap = {0,NULL};
185 	colormap_alloc(&colorMap, 1);
186 	for(c=0; c<3; c++)
187 		colorMap.colorValue[0].color[c] = color[c];
188 	colorMap.colorValue[0].value = value;
189 	return colorMap;
190 }
191 /******************************************************************************************************************************/
add_to_colorMap(ColorMap * colorMap,gdouble color[],gdouble value)192 static void add_to_colorMap(ColorMap* colorMap, gdouble color[], gdouble value)
193 {
194 	gint i;
195 	gint c;
196 	OneColorValue* colorValue = NULL;
197 	colorValue = g_malloc((colorMap->numberOfColors+1)*sizeof(OneColorValue));
198 	for(i=0; i<colorMap->numberOfColors; i++)
199 		colorValue[i] = colorMap->colorValue[i];
200 
201 	for(c=0;c<3;c++)
202 		colorValue[colorMap->numberOfColors].color[c] = color[c];
203 	colorValue[colorMap->numberOfColors].value = value;
204 	g_free( colorMap->colorValue);
205 	colorMap->colorValue = colorValue;
206 	colorMap->numberOfColors++;
207 }
208 /******************************************************************************************************************************/
sort_colorMap(ColorMap * colorMap)209 static void sort_colorMap(ColorMap* colorMap)
210 {
211 	gint i;
212 	gint j;
213 	gint k;
214 	OneColorValue tmp;
215 	for(i=0;i<colorMap->numberOfColors-1;i++)
216 	{
217 		k = i;
218 		for(j=i+1;j<colorMap->numberOfColors;j++)
219 			if(colorMap->colorValue[k].value>colorMap->colorValue[j].value)
220 				k = j;
221 		if(k != i)
222 		{
223 			tmp = colorMap->colorValue[i];
224 			colorMap->colorValue[i] = colorMap->colorValue[k];
225 			colorMap->colorValue[k] = tmp;
226 		}
227 	}
228 }
229 /******************************************************************************************************************************/
new_colorMap_min_max_multicolor(gdouble minValue,gdouble maxValue)230 static ColorMap*  new_colorMap_min_max_multicolor(gdouble minValue, gdouble maxValue)
231 {
232 	gint i;
233 	gint j;
234 	gint k;
235 	gdouble h = 0;
236 	gint ns = 4;
237 	gint nc = 20;
238 	gint n = nc *ns+1;
239 	gdouble color[3];
240 	ColorMap* colorMap;
241 
242 	h = (maxValue-minValue)/(n-1) ;
243 	color[0] = 1.0; color[1] = 0.0; color[2] = 0.0;
244 
245 	colorMap = g_malloc(sizeof(ColorMap));
246 	*colorMap = new_colorMap(color, minValue);
247 	k = 1;
248 	for(j=0;j<ns;j++)
249 	for(i=0;i<nc;i++)
250 	{
251 
252 		if(j==0) color[1] += 1.0/nc;
253 		if(j==1) color[0] -= 1.0/nc;
254 		if(j==2) color[2] += 1.0/nc;
255 		if(j==3) color[1] -= 1.0/nc;
256 		add_to_colorMap(colorMap, color, minValue +k*h);
257 		k++;
258 	}
259 	sort_colorMap(colorMap);
260 	return colorMap;
261 }
262 /******************************************************************************************************************************/
new_colorMap_min_max_unicolor(gdouble minValue,gdouble maxValue,gdouble Color[])263 static ColorMap*  new_colorMap_min_max_unicolor(gdouble minValue, gdouble maxValue, gdouble Color[])
264 {
265 	gdouble color[3];
266 	ColorMap* colorMap;
267 	gint c;
268 
269 	for(c=0;c<3;c++) color[c] = Color[c];
270 	colorMap = g_malloc(sizeof(ColorMap));
271 	*colorMap = new_colorMap(color, minValue);
272 	add_to_colorMap(colorMap, color, maxValue );
273 	sort_colorMap(colorMap);
274 	return colorMap;
275 }
276 /******************************************************************************************************************************/
new_colorMap_min_max_2colors(gdouble minValue,gdouble maxValue,gdouble Color1[],gdouble Color2[])277 static ColorMap*  new_colorMap_min_max_2colors(gdouble minValue, gdouble maxValue, gdouble Color1[], gdouble Color2[])
278 {
279 	gdouble color[3];
280 	gdouble color1[3];
281 	gdouble color2[3];
282 	ColorMap* colorMap;
283 	gint c;
284 
285 	gdouble max1;
286 	gdouble max2;
287 
288 	for(c=0;c<3;c++) color1[c] = Color1[c];
289 	for(c=0;c<3;c++) color2[c] = Color2[c];
290 
291 	max1 = color1[0];
292 	if(max1<color1[1]) max1 = color1[1];
293 	if(max1<color1[2]) max1 = color1[2];
294 	if(max1<1e-3)
295 	{
296 		color1[0] = 1.0;
297 		color1[1] = 1.0;
298 		color1[2] = 1.0;
299 		max1 = 1.0;
300 	}
301 	max2 = color2[0];
302 	if(max2<color2[1]) max2 = color2[1];
303 	if(max2<color2[2]) max2 = color2[2];
304 	if(max2<1e-3)
305 	{
306 		color2[0] = 1.0;
307 		color2[1] = 1.0;
308 		color2[2] = 1.0;
309 		max2 = 1.0;
310 	}
311 
312 	color[0] = 0; color[1] = 0; color[2] = 0;
313 	for(c=0;c<3;c++) color1[c] /= max1;
314 	for(c=0;c<3;c++) color2[c] /= max2;
315 	colorMap = g_malloc(sizeof(ColorMap));
316 	*colorMap = new_colorMap(color1, minValue);
317 	add_to_colorMap(colorMap, color, minValue+(maxValue-minValue)/2 );
318 	add_to_colorMap(colorMap, color2, maxValue );
319 
320 	sort_colorMap(colorMap);
321 	return colorMap;
322 }
323 /************************************************************************************************************/
new_colorMap_min_max(gdouble minValue,gdouble maxValue,gint colorMapType,gdouble colorMapColors[3][3])324 static ColorMap*  new_colorMap_min_max(gdouble minValue, gdouble maxValue, gint colorMapType, gdouble colorMapColors[3][3])
325 {
326 	if(colorMapType == 1) return new_colorMap_min_max_multicolor(minValue,maxValue);
327 	else if(colorMapType == 2)
328 	return new_colorMap_min_max_2colors(minValue,maxValue, colorMapColors[0], colorMapColors[1]);
329 	else return new_colorMap_min_max_unicolor(minValue,maxValue, colorMapColors[2]);
330 }
331 /******************************************************************************************************************************/
set_Color_From_colorMap(ColorMap * colorMap,gdouble color[],gdouble value)332 static void  set_Color_From_colorMap(ColorMap* colorMap, gdouble color[], gdouble value)
333 {
334 	gint i = 0;
335 	gint k = 0;
336 	gint c;
337 	gdouble l,l1,l2;
338 	if(colorMap->numberOfColors<1)
339 	{
340 		for(c=0;c<3;c++)
341 			color[c] = 0.5;
342 		return;
343 	}
344 	if(value<=colorMap->colorValue[i].value)
345 	{
346 		for(c=0;c<3;c++)
347 			color[c] = colorMap->colorValue[i].color[c];
348 		return;
349 	}
350 	i = colorMap->numberOfColors-1;
351 	if(value>=colorMap->colorValue[i].value)
352 	{
353 		for(c=0;c<3;c++)
354 			color[c] = colorMap->colorValue[i].color[c];
355 		return;
356 	}
357 
358 	k = 0;
359 	for(i=1;i<colorMap->numberOfColors-1;i++)
360 	{
361 		if(value>=colorMap->colorValue[i].value && value<=colorMap->colorValue[i+1].value)
362 		{
363 			k = i;
364 			break;
365 		}
366 	}
367 	l = colorMap->colorValue[k+1].value-colorMap->colorValue[k].value;
368 	l1 = value-colorMap->colorValue[k].value;
369 	l2 = l-l1;
370 	if(l>0 && l1>=0 && l2>=0)
371 	{
372 		l1 = l1/l;
373 		l2 = l2/l;
374 		for(c=0;c<3;c++)
375 			color[c] = colorMap->colorValue[k].color[c]*l2+colorMap->colorValue[k+1].color[c]*l1;
376 	}
377 	else
378 	for(c=0;c<3;c++)
379 		color[c] = colorMap->colorValue[k].color[c];
380 }
381 /**********************************************************************************/
gabedit_contoursplot_cairo_image(cairo_t * cr,GtkWidget * widget,gint x,gint y,gint w,gint h,cairo_surface_t * image)382 static void gabedit_contoursplot_cairo_image(cairo_t* cr, GtkWidget *widget, gint x, gint y, gint w, gint h, cairo_surface_t *image)
383 {
384 	gint ow = 1;
385 	gint oh = 1;
386 	if(!image) return;
387 	if(x<0||y<0) return;
388 	/* printf("x = %d y = %d w = %d h = %d\n",x,y,w,h);*/
389 	ow = cairo_image_surface_get_width (image);
390 	oh = cairo_image_surface_get_height (image);
391 
392 	cairo_save (cr);
393 
394 	cairo_translate (cr, x,y);
395 	cairo_scale (cr, (gdouble)w/ow, (gdouble)h/oh);
396 	cairo_set_source_surface (cr, image, 0, 0);
397 	cairo_paint (cr);
398 
399 	cairo_stroke (cr);
400 	cairo_restore (cr);
401 }
402 /**********************************************************************************/
gabedit_contoursplot_cairo_string(cairo_t * cr,GtkWidget * widget,GdkGC * gc,gint x,gint y,G_CONST_RETURN gchar * str,gboolean centerX,gboolean centerY,gdouble angle)403 static void gabedit_contoursplot_cairo_string(cairo_t* cr, GtkWidget *widget, GdkGC* gc, gint x, gint y, G_CONST_RETURN gchar* str, gboolean centerX, gboolean centerY, gdouble angle)
404 {
405 	PangoLayout* pango = get_pango_str(GABEDIT_ContoursPLOT(widget), str);
406 	gabedit_contoursplot_cairo_layout(cr, x, y, pango, centerX,  centerY, angle) ;
407 	g_object_unref(G_OBJECT(pango));
408 }
409 /*****************************************************************************/
gabedit_contoursplot_cairo_line(cairo_t * cr,GtkWidget * widget,GdkGC * gc,gdouble x1,gdouble y1,gdouble x2,gdouble y2)410 static void gabedit_contoursplot_cairo_line(cairo_t *cr,  GtkWidget* widget, GdkGC* gc, gdouble x1,gdouble y1,gdouble x2,gdouble y2)
411 {
412 	GdkGCValues values;
413 	GdkColor color;
414 	double r,g,b;
415 	GdkColormap *colormap;
416 	double dashes[] = {5.0,  /* ink */
417 		           5.0,  /* skip */
418 			   10.0,  /* ink */
419 			   5.0   /* skip*/
420 	};
421 	int    ndash  = sizeof (dashes)/sizeof(dashes[0]);
422 	double offset = -5.0;
423 
424 
425 	if(!cr) return;
426 	if(!gc) return;
427 	cairo_save (cr);
428 	gdk_gc_get_values(gc, &values);
429 
430 	switch(values.cap_style)
431 	{
432 		case GDK_CAP_NOT_LAST:
433 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
434 		case GDK_CAP_BUTT:
435 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
436 		case GDK_CAP_ROUND:
437 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); break;
438 		case GDK_CAP_PROJECTING:
439 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); break;
440 		default:
441 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
442 	}
443 	switch(values.join_style)
444 	{
445 		case GDK_JOIN_MITER:
446 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);break;
447 		case GDK_JOIN_ROUND :
448 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);break;
449 		case GDK_JOIN_BEVEL :
450 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);break;
451 		default:
452 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);break;
453 	}
454 	switch(values.line_style)
455 	{
456 		case GDK_LINE_SOLID : ndash = 0; break;
457 		case GDK_LINE_ON_OFF_DASH : ndash = 2; break;
458 		case GDK_LINE_DOUBLE_DASH : break;
459 		default  : ndash = 0;
460 	}
461    	colormap  = gdk_window_get_colormap(widget->window);
462         gdk_colormap_query_color(colormap, values.foreground.pixel,&color);
463 
464 	if( ndash != 0) cairo_set_dash (cr, dashes, ndash, offset);
465 
466 	r = SCALE(color.red);
467 	g = SCALE(color.green);
468 	b = SCALE(color.blue);
469 	cairo_set_source_rgba (cr, r, g, b, 1.0);
470 	if(values.line_width<1) values.line_width = 1;
471 
472 	cairo_set_line_width (cr, values.line_width);
473 	cairo_move_to (cr, x1, y1);
474 	cairo_line_to (cr, x2, y2);
475 	cairo_stroke (cr);
476 	cairo_restore (cr);
477 }
478 /*****************************************************************************/
gabedit_contoursplot_cairo_lines(cairo_t * cr,GtkWidget * widget,GdkGC * gc,GdkPoint * points,gint size)479 static void gabedit_contoursplot_cairo_lines(cairo_t *cr,  GtkWidget* widget, GdkGC* gc, GdkPoint* points, gint size)
480 {
481 	gint i;
482 	for(i=0;i<size-1;i++)
483 		gabedit_contoursplot_cairo_line(cr, widget, gc, points[i].x, points[i].y, points[i+1].x, points[i+1].y);
484 }
485 /*****************************************************************************/
gabedit_contoursplot_cairo_rectangle(cairo_t * cr,GtkWidget * widget,GdkGC * gc,gboolean fill,gdouble x1,gdouble y1,gdouble w,gdouble h)486 static void gabedit_contoursplot_cairo_rectangle(cairo_t *cr,  GtkWidget* widget, GdkGC* gc, gboolean fill, gdouble x1,gdouble y1,gdouble w,gdouble h)
487 {
488 	GdkGCValues values;
489 	GdkColor color;
490 	double r,g,b;
491 	GdkColormap *colormap;
492 	double dashes[] = {5.0,  /* ink */
493 		           5.0,  /* skip */
494 			   10.0,  /* ink */
495 			   5.0   /* skip*/
496 	};
497 	int    ndash  = sizeof (dashes)/sizeof(dashes[0]);
498 	double offset = 0.0;
499 
500 
501 	if(!cr) return;
502 	if(!gc) return;
503 	cairo_save (cr);
504 	gdk_gc_get_values(gc, &values);
505 
506 	switch(values.cap_style)
507 	{
508 		case GDK_CAP_NOT_LAST:
509 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
510 		case GDK_CAP_BUTT:
511 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
512 		case GDK_CAP_ROUND:
513 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); break;
514 		case GDK_CAP_PROJECTING:
515 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); break;
516 		default:
517 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
518 	}
519 	switch(values.join_style)
520 	{
521 		case GDK_JOIN_MITER:
522 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);break;
523 		case GDK_JOIN_ROUND :
524 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);break;
525 		case GDK_JOIN_BEVEL :
526 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);break;
527 		default:
528 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);break;
529 	}
530 	switch(values.line_style)
531 	{
532 		case GDK_LINE_SOLID : ndash = 0; break;
533 		case GDK_LINE_ON_OFF_DASH : ndash = 2; break;
534 		case GDK_LINE_DOUBLE_DASH : break;
535 		default  : ndash = 0;
536 	}
537    	colormap  = gdk_window_get_colormap(widget->window);
538         gdk_colormap_query_color(colormap, values.foreground.pixel,&color);
539 
540 	if( ndash != 0) cairo_set_dash (cr, dashes, ndash, offset);
541 
542 	r = SCALE(color.red);
543 	g = SCALE(color.green);
544 	b = SCALE(color.blue);
545 	cairo_set_source_rgba (cr, r, g, b, 1.0);
546 
547 	cairo_move_to (cr, x1, y1);
548 	cairo_rel_line_to (cr, w, 0);
549 	cairo_rel_line_to (cr, 0, h);
550 	cairo_rel_line_to (cr, -w, 0);
551 	cairo_close_path (cr);
552 	if(values.line_width<1) values.line_width = 1;
553 	if(fill) cairo_fill(cr);
554 	else cairo_set_line_width (cr, values.line_width);
555 	cairo_stroke (cr);
556 	cairo_restore (cr);
557 }
558 /*****************************************************************************/
559 /*
560 static void gabedit_contoursplot_cairo_cercle(cairo_t *cr,  GtkWidget* widget, GdkGC* gc,
561 		gint xc,gint yc,gint rayon)
562 {
563 	GdkGCValues values;
564 	GdkColor color;
565 	double r,g,b;
566 	GdkColormap *colormap;
567 	if(!cr) return;
568 	if(!gc) return;
569 	cairo_save (cr);
570 	gdk_gc_get_values(gc, &values);
571 
572 	switch(values.cap_style)
573 	{
574 		case GDK_CAP_NOT_LAST:
575 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
576 		case GDK_CAP_BUTT:
577 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
578 		case GDK_CAP_ROUND:
579 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); break;
580 		case GDK_CAP_PROJECTING:
581 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); break;
582 		default:
583 			cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); break;
584 
585 	}
586 	switch(values.join_style)
587 	{
588 		case GDK_JOIN_MITER:
589 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);break;
590 		case GDK_JOIN_ROUND :
591 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);break;
592 		case GDK_JOIN_BEVEL :
593 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);break;
594 		default:
595 			cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);break;
596 	}
597    	colormap  = gdk_window_get_colormap(widget->window);
598         gdk_colormap_query_color(colormap, values.foreground.pixel,&color);
599 	r = SCALE(color.red);
600 	g = SCALE(color.green);
601 	b = SCALE(color.blue);
602 	cairo_set_source_rgba (cr, r, g, b, 1.0);
603 	if(values.line_width<1) values.line_width = 1;
604 
605 	cairo_set_line_width (cr, values.line_width);
606 	cairo_arc (cr, xc, yc, rayon, 0, 2 * M_PI);
607 	if(values.fill==GDK_SOLID) cairo_fill (cr);
608 	cairo_stroke (cr);
609 	cairo_restore (cr);
610 }
611 */
612 /**********************************************************************************/
gabedit_contoursplot_cairo_layout(cairo_t * cr,gdouble x,gdouble y,PangoLayout * layout,gboolean centerX,gboolean centerY,gdouble angle)613 static void gabedit_contoursplot_cairo_layout(cairo_t* cr, gdouble x, gdouble y, PangoLayout *layout, gboolean centerX, gboolean centerY, gdouble angle)
614 {
615 	cairo_save (cr);
616 	if(centerX || centerY)
617 	{
618 		gint w;
619 		gint h;
620 		pango_layout_get_size(layout,&w,&h);
621 		if(centerX) x-=w/2/PANGO_SCALE*cos(angle)-h/2/PANGO_SCALE*sin(angle);
622 		if(centerY) y-=w/2/PANGO_SCALE*sin(angle)+h/2/PANGO_SCALE*cos(angle);
623 	}
624 	cairo_move_to(cr, x,y);
625 	cairo_rotate(cr, angle);
626 
627 	pango_cairo_show_layout(cr,layout);
628 	cairo_stroke (cr);
629 	cairo_restore (cr);
630 }
631 /****************************************************************************************/
contoursplot_cairo_image(GabeditContoursPlot * contoursplot,cairo_t * cr,GtkWidget * widget,gint x,gint y,gint w,gint h,cairo_surface_t * image)632 static void contoursplot_cairo_image(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget *widget, gint x, gint y, gint w, gint h, cairo_surface_t *image)
633 {
634 	gabedit_contoursplot_cairo_image(cr,  widget, x, y, w, h, image);
635 	if(contoursplot->cairo_export)
636 		gabedit_contoursplot_cairo_image(contoursplot->cairo_export,  widget, x, y, w, h, image);
637 }
638 /****************************************************************************************/
contoursplot_cairo_string(GabeditContoursPlot * contoursplot,cairo_t * cr,GtkWidget * widget,GdkGC * gc,gint x,gint y,G_CONST_RETURN gchar * str,gboolean centerX,gboolean centerY,gdouble angle)639 static void contoursplot_cairo_string(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gint x, gint y, G_CONST_RETURN gchar* str, gboolean centerX, gboolean centerY, gdouble angle)
640 {
641 
642 	gabedit_contoursplot_cairo_string(cr,  widget, gc, x, y, str, centerX, centerY, angle);
643 	if(contoursplot->cairo_export)
644 		gabedit_contoursplot_cairo_string(contoursplot->cairo_export,  widget, gc,  x, y, str, centerX, centerY, angle);
645 }
646 /****************************************************************************************/
contoursplot_cairo_line(GabeditContoursPlot * contoursplot,cairo_t * cr,GtkWidget * widget,GdkGC * gc,gdouble x1,gdouble y1,gdouble x2,gdouble y2)647 static void contoursplot_cairo_line(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gdouble x1,gdouble y1,gdouble x2,gdouble y2)
648 {
649 	gabedit_contoursplot_cairo_line(cr,  widget, gc, x1, y1, x2, y2);
650 	if(contoursplot->cairo_export)
651 		gabedit_contoursplot_cairo_line(contoursplot->cairo_export,  widget, gc,  x1, y1, x2, y2);
652 }
653 /****************************************************************************************/
contoursplot_cairo_rectangle(GabeditContoursPlot * contoursplot,cairo_t * cr,GtkWidget * widget,GdkGC * gc,gboolean fill,gdouble x1,gdouble y1,gdouble x2,gdouble y2)654 static void contoursplot_cairo_rectangle(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gboolean fill, gdouble x1,gdouble y1,gdouble x2,gdouble y2)
655 {
656 	gabedit_contoursplot_cairo_rectangle(cr,  widget, gc, fill, x1, y1, x2, y2);
657 	if(contoursplot->cairo_export)
658 		gabedit_contoursplot_cairo_rectangle(contoursplot->cairo_export,  widget, gc,  fill, x1, y1, x2, y2);
659 }
660 /****************************************************************************************/
contoursplot_cairo_lines(GabeditContoursPlot * contoursplot,cairo_t * cr,GtkWidget * widget,GdkGC * gc,GdkPoint * points,gint size)661 static void contoursplot_cairo_lines(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, GdkPoint* points, gint size)
662 {
663 	gabedit_contoursplot_cairo_lines(cr,  widget, gc, points, 2);
664 	if(contoursplot->cairo_export && size>0)
665 	{
666 		GdkPoint* pointsScal = g_malloc(size*sizeof(GdkPoint));
667 		gint i;
668 		if(!pointsScal) return;
669 		for(i=0;i<size;i++)
670 		{
671 			pointsScal[i].x = points[i].x + contoursplot->plotting_rect.x;
672 			pointsScal[i].y = points[i].y + contoursplot->plotting_rect.y;
673 		}
674 		gabedit_contoursplot_cairo_lines(contoursplot->cairo_export,  widget, gc, pointsScal, 2);
675 		if(pointsScal) g_free(pointsScal);
676 	}
677 }
678 /****************************************************************************************/
679 /*
680 static void contoursplot_cairo_cercle(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gint xc,gint yc,gint rayon)
681 {
682 	gabedit_contoursplot_cairo_cercle(cr,  widget, gc, xc, yc, rayon);
683 	if(contoursplot->cairo_export)
684 		gabedit_contoursplot_cairo_cercle(contoursplot->cairo_export,  widget, gc, xc, yc, rayon);
685 }
686 */
687 /****************************************************************************************/
contoursplot_cairo_layout(GabeditContoursPlot * contoursplot,cairo_t * cr,gdouble x,gdouble y,PangoLayout * layout,gboolean centerX,gboolean centerY,gdouble angle)688 static void contoursplot_cairo_layout(GabeditContoursPlot *contoursplot, cairo_t* cr,   gdouble x, gdouble y, PangoLayout *layout, gboolean centerX, gboolean centerY, gdouble angle)
689 {
690 	gabedit_contoursplot_cairo_layout(cr, x, y, layout, centerX, centerY, angle);
691 	if(contoursplot->cairo_export)
692 	{
693 		if(cr == contoursplot->cairo_area)
694 		{
695 			x += contoursplot->plotting_rect.x;
696 			y += contoursplot->plotting_rect.y;
697 		}
698 		gabedit_contoursplot_cairo_layout(contoursplot->cairo_export,  x, y, layout, centerX, centerY, angle);
699 	}
700 }
701 /****************************************************************************************/
702 /*
703 static void list_utf8()
704 {
705 	gchar tmp[10000];
706 	gchar t[10000];
707 	GtkWidget* dialog = NULL;
708 	gint i=32;
709 	sprintf(tmp,"%d(<span>&#%d;</span>)  ",i,i);
710 
711 	for(i=9600;i<9700;i++)
712 	{
713 
714 		sprintf(t,"%s",tmp);
715 		sprintf(tmp,"%s %d(<span>&#%d;</span>)  ",t,i,i);
716 	}
717 	dialog = gtk_message_dialog_new_with_markup (NULL,
718 			GTK_DIALOG_DESTROY_WITH_PARENT,
719 			GTK_MESSAGE_INFO,
720 			GTK_BUTTONS_YES_NO,
721 			tmp
722 			);
723 	gtk_dialog_run (GTK_DIALOG (dialog));
724 	gtk_widget_destroy (dialog);
725 }
726 */
727 /****************************************************************************************/
get_parent_window(GtkWidget * widget)728 static GtkWidget* get_parent_window(GtkWidget* widget)
729 {
730 	GtkWidget* parent = NULL;
731 	GtkWidget* child = widget;
732 	do
733 	{
734 		parent = gtk_widget_get_parent(child);
735 		child = parent;
736 	}
737 	while( parent && !GTK_IS_WINDOW(parent));
738 	return parent;
739 }
740 /****************************************************************************************/
destroy_contoursplot_window(GtkWidget * contoursplot)741 static void destroy_contoursplot_window(GtkWidget* contoursplot)
742 {
743 	GtkWidget* parentWindow;
744 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
745 	if(parentWindow) gtk_object_destroy (GTK_OBJECT(parentWindow));
746 }
747 /****************************************************************************************/
destroy_data_dialog(GtkWidget * win,GdkEvent * event,gpointer user_data)748 static void destroy_data_dialog(GtkWidget* win, GdkEvent  *event, gpointer user_data)
749 {
750   	gtk_object_destroy (GTK_OBJECT(win));
751 }
752 /********************************************************************************/
remove_all_data(GtkWidget * contoursplot,gint response_id)753 static gboolean remove_all_data(GtkWidget* contoursplot, gint response_id)
754 {
755 	if(response_id != GTK_RESPONSE_YES) return FALSE;
756 	if(!contoursplot) return FALSE;
757 	if(GABEDIT_ContoursPLOT(contoursplot)->data_list)
758 	{
759 		g_list_foreach(GABEDIT_ContoursPLOT(contoursplot)->data_list, (GFunc)g_free, NULL);
760 		g_list_free(GABEDIT_ContoursPLOT(contoursplot)->data_list);
761 		GABEDIT_ContoursPLOT(contoursplot)->data_list = NULL;
762 	}
763 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
764 	return TRUE;
765 }
766 /********************************************************************************/
remove_all_data_dlg(GtkWidget * contoursplot)767 static void remove_all_data_dlg(GtkWidget* contoursplot)
768 {
769 	GtkWidget* parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
770 	GtkWidget* dialog = gtk_message_dialog_new (GTK_WINDOW(parentWindow),
771 			GTK_DIALOG_DESTROY_WITH_PARENT,
772 			GTK_MESSAGE_QUESTION,
773 			GTK_BUTTONS_YES_NO,
774 		       _("Are you sure to remove all data ?")
775 			);
776 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);
777 	g_signal_connect_swapped(dialog, "response", G_CALLBACK (remove_all_data), contoursplot);
778 	gtk_dialog_run (GTK_DIALOG (dialog));
779 	gtk_widget_destroy (dialog);
780 }
781 /*****************************************************************************************/
file_chooser_set_filters(GtkFileChooser * fileChooser,gchar ** patterns)782 static void file_chooser_set_filters(GtkFileChooser *fileChooser,gchar **patterns)
783 {
784 	GtkFileFilter *filter;
785 	GtkFileFilter *filter0 = NULL;
786 	gint n = 0;
787 
788 	g_return_if_fail (fileChooser != NULL);
789 	g_return_if_fail (GTK_IS_FILE_CHOOSER(fileChooser));
790 	g_return_if_fail (patterns != NULL);
791 	while(patterns[n])
792 	{
793 		filter = gtk_file_filter_new ();
794 		gtk_file_filter_set_name (filter, patterns[n]);
795 		gtk_file_filter_add_pattern (filter, patterns[n]);
796 		gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fileChooser), filter);
797 		if(n==0) filter0 = filter;
798 		n++;
799 	}
800 	if(filter0)gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fileChooser), filter0);
801 }
802 /********************************************************************************/
new_file_chooser_open(GtkWidget * parentWindow,GCallback * func,gchar * title,gchar ** patternsfiles)803 static GtkWidget* new_file_chooser_open(GtkWidget* parentWindow, GCallback *func, gchar* title, gchar** patternsfiles)
804 {
805 	GtkWidget* filesel = NULL;
806 	filesel = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_OPEN, "file-system-backend", "gtk+", "select-multiple", FALSE, NULL);
807 	gtk_window_set_title (GTK_WINDOW (filesel), title);
808 	gtk_dialog_add_buttons (GTK_DIALOG (filesel), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
809 	gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_OK);
810 
811 	if(parentWindow) gtk_window_set_transient_for(GTK_WINDOW(filesel),GTK_WINDOW(parentWindow));
812 
813 	gtk_window_set_modal (GTK_WINDOW (filesel), TRUE);
814 	g_signal_connect (filesel, "response",  G_CALLBACK (func),GTK_OBJECT(filesel));
815 	g_signal_connect_after (filesel, "response", G_CALLBACK (gtk_widget_destroy),GTK_OBJECT(filesel));
816 	file_chooser_set_filters(GTK_FILE_CHOOSER(filesel),patternsfiles);
817 	gtk_widget_show(filesel);
818 	return filesel;
819 }
820 /********************************************************************************/
new_file_chooser_save(GtkWidget * parentWindow,GCallback * func,gchar * title,gchar ** patternsfiles)821 static GtkWidget* new_file_chooser_save(GtkWidget* parentWindow, GCallback *func, gchar* title, gchar** patternsfiles)
822 {
823 	GtkWidget* filesel = NULL;
824 	filesel = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_SAVE, "file-system-backend", "gtk+", "select-multiple", FALSE, NULL);
825 	gtk_window_set_title (GTK_WINDOW (filesel), title);
826 	gtk_dialog_add_buttons (GTK_DIALOG (filesel), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
827 	gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_OK);
828 
829 	if(parentWindow) gtk_window_set_transient_for(GTK_WINDOW(filesel),GTK_WINDOW(parentWindow));
830 
831 	gtk_window_set_modal (GTK_WINDOW (filesel), TRUE);
832 	g_signal_connect (filesel, "response",  G_CALLBACK (func),GTK_OBJECT(filesel));
833 	g_signal_connect_after (filesel, "response", G_CALLBACK (gtk_widget_destroy),GTK_OBJECT(filesel));
834 	file_chooser_set_filters(GTK_FILE_CHOOSER(filesel),patternsfiles);
835 	gtk_widget_show(filesel);
836 	return filesel;
837 }
838 /****************************************************************************************/
get_interpolatedValueData(ContoursPlotData * data,gdouble x,gdouble y,gdouble * zv,gdouble * pdzdx,gdouble * pdzdy,gdouble * pd2zdx2,gdouble * pd2zdy2,gdouble * pd2zdxdy)839 static void get_interpolatedValueData(ContoursPlotData* data, gdouble x, gdouble y, gdouble* zv, gdouble* pdzdx, gdouble* pdzdy, gdouble* pd2zdx2, gdouble* pd2zdy2, gdouble* pd2zdxdy)
840 {
841 	gint xsize = data->xsize;
842 	gint ysize = data->ysize;
843 	gdouble dx = (data->xmax-data->xmin)/(xsize-1);
844 	gdouble dy = (data->ymax-data->ymin)/(ysize-1);
845 	gint ix = (gint)((x-data->xmin)/dx);
846 	gint iy = (gint)((y-data->ymin)/dy);
847 	gint ix1 = ix+1;
848 	gint iy1 = iy+1;
849 	gint ixp = (ix+1)%xsize;
850 	gint ixm = (ix-1+xsize)%xsize;
851 	gint ix1p = (ix1+1)%xsize;
852 	gint ix1m = (ix1-1+xsize)%xsize;
853 	gint iyp = (iy+1)%ysize;
854 	gint iym = (iy-1+ysize)%ysize;
855 	gint iy1p = (iy1+1)%ysize;
856 	gint iy1m = (iy1-1+ysize)%ysize;
857 	gdouble xl = data->xmin+ix*dx;
858 	gdouble xu = data->xmin+(ix+1)*dx;
859 	gdouble yl = data->ymin+iy*dy;
860 	gdouble yu = data->ymin+(iy+1)*dy;
861 	gdouble* zValues = data->zValues;
862 	gdouble z[4] = { zValues[ix*ysize+iy], zValues[ix1*ysize+iy], zValues[ix1*ysize+iy1], zValues[ix*ysize+iy1]};
863 	gdouble dzdx[4] = {
864 	  (zValues[ixp*ysize+iy] - zValues[ixm*ysize+iy])/dx/2,
865 	  (zValues[ix1p*ysize+iy] - zValues[ix1m*ysize+iy])/dx/2,
866 	  (zValues[ix1p*ysize+iy1] - zValues[ix1m*ysize+iy1])/dx/2,
867 	  (zValues[ixp*ysize+iy1] - zValues[ixm*ysize+iy1])/dx/2
868 	};
869 	gdouble dzdy[4] = {
870 	  (zValues[ix*ysize+iyp] - zValues[ix*ysize+iym])/dy/2,
871 	  (zValues[ix1*ysize+iyp] - zValues[ix1*ysize+iym])/dy/2,
872 	  (zValues[ix1*ysize+iy1p] - zValues[ix1*ysize+iy1m])/dy/2,
873 	  (zValues[ix*ysize+iy1p] - zValues[ix*ysize+iy1m])/dy/2
874 	};
875 	gdouble d2zdxdy[4] = {
876 	  (zValues[ixp*ysize+iyp] + zValues[ixm*ysize+iym]-zValues[ixp*ysize+iym]-zValues[ixm*ysize+iyp])/dx/dy/4,
877 	  (zValues[ix1p*ysize+iyp] + zValues[ix1m*ysize+iym]-zValues[ix1p*ysize+iym]-zValues[ix1m*ysize+iyp])/dx/dy/4,
878 	  (zValues[ix1p*ysize+iy1p] + zValues[ix1m*ysize+iy1m]-zValues[ix1p*ysize+iy1m]-zValues[ix1m*ysize+iy1p])/dx/dy/4,
879 	  (zValues[ixp*ysize+iy1p] + zValues[ixm*ysize+iy1m]-zValues[ixp*ysize+iy1m]-zValues[ixm*ysize+iy1p])/dx/dy/4
880 	};
881 	*zv = 0;
882 	biCubicInterpolation( z, dzdx, dzdy, d2zdxdy, xl, xu, yl,  yu,  x,  y, zv, pdzdx,pdzdy, pd2zdx2, pd2zdy2, pd2zdxdy);
883 
884 }
885 /****************************************************************************************/
get_interpolatedValue(GtkWidget * contoursplot,ContoursPlotData * data,gdouble x,gdouble y,gdouble * zv,gdouble * pdzdx,gdouble * pdzdy,gdouble * pd2zdx2,gdouble * pd2zdy2,gdouble * pd2zdxdy)886 static void get_interpolatedValue(GtkWidget* contoursplot, ContoursPlotData* data, gdouble x, gdouble y, gdouble* zv, gdouble* pdzdx, gdouble* pdzdy, gdouble* pd2zdx2, gdouble* pd2zdy2, gdouble* pd2zdxdy)
887 {
888 
889 	if(!GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap) return;
890 	if(!zv) return;
891 	if(data)
892 	{
893 		get_interpolatedValueData(data, x, y, zv, pdzdx, pdzdy, pd2zdx2, pd2zdy2, pd2zdxdy);
894 	}
895 	else
896 	{
897 		GList *current_node;
898 		current_node=g_list_last(GABEDIT_ContoursPLOT(contoursplot)->data_list);
899 		data=(ContoursPlotData*)current_node->data;
900 		get_interpolatedValueData(data, x, y, zv, pdzdx, pdzdy, pd2zdx2, pd2zdy2, pd2zdxdy);
901 	}
902 }
903 /****************************************************************************************/
reset_contour_lines_styles(GtkWidget * contoursplot,ContoursPlotData * data)904 static void reset_contour_lines_styles(GtkWidget* contoursplot, ContoursPlotData* data)
905 {
906 
907 	gint loop;
908 	if(!GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap) return;
909 	if(data)
910 	{
911 		for(loop=0;loop<data->nContours; loop++)
912 		{
913 			gdouble value = data->contours[loop].value;
914 			data->contours[loop].line_style = GDK_LINE_SOLID;
915 			if(GABEDIT_ContoursPLOT(contoursplot)->dashed_negative_contours && value<0)
916 				data->contours[loop].line_style = GDK_LINE_ON_OFF_DASH;
917 		}
918 	}
919 	else
920 	{
921 		GList *current_node;
922 		current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
923 		for (; current_node!=NULL; current_node=current_node->next)
924 		{
925 			data=(ContoursPlotData*)current_node->data;
926 			for(loop=0;loop<data->nContours; loop++)
927 			{
928 				gdouble value = data->contours[loop].value;
929 				data->contours[loop].line_style = GDK_LINE_SOLID;
930 				if(GABEDIT_ContoursPLOT(contoursplot)->dashed_negative_contours && value<0)
931 					data->contours[loop].line_style = GDK_LINE_ON_OFF_DASH;
932 			}
933 		}
934 	}
935 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
936 }
937 /****************************************************************************************/
reset_contour_colors(GtkWidget * contoursplot,ContoursPlotData * data)938 static void reset_contour_colors(GtkWidget* contoursplot, ContoursPlotData* data)
939 {
940 
941 	gint loop;
942 	if(!GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap) return;
943 	if(data)
944 	{
945 		for(loop=0;loop<data->nContours; loop++)
946 		{
947 			gdouble value = data->contours[loop].value;
948 			gdouble color[3];
949 			set_Color_From_colorMap(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap, color, value);
950 			data->contours[loop].line_color.red=(gushort)(color[0]*65535);
951 			data->contours[loop].line_color.green=(gushort)(color[1]*65535);
952 			data->contours[loop].line_color.blue=(gushort)(color[2]*65535);
953 		}
954 	}
955 	else
956 	{
957 		GList *current_node;
958 		current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
959 		for (; current_node!=NULL; current_node=current_node->next)
960 		{
961 			data=(ContoursPlotData*)current_node->data;
962 			for(loop=0;loop<data->nContours; loop++)
963 			{
964 				gdouble value = data->contours[loop].value;
965 				gdouble color[3];
966 				set_Color_From_colorMap(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap, color, value);
967 				data->contours[loop].line_color.red=(gushort)(color[0]*65535);
968 				data->contours[loop].line_color.green=(gushort)(color[1]*65535);
969 				data->contours[loop].line_color.blue=(gushort)(color[2]*65535);
970 			}
971 		}
972 	}
973 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
974 }
975 /****************************************************************************************/
contoursplot_build_points_contour(GabeditContoursPlot * contoursplot,ContourData * contour)976 static void contoursplot_build_points_contour(GabeditContoursPlot *contoursplot, ContourData *contour)
977 {
978 	GtkWidget *widget;
979 	if (contoursplot == NULL) return;
980 	if(contoursplot->data_list == NULL) return;
981 
982 	widget=GTK_WIDGET(contoursplot);
983 	if(contour->point_pango != NULL) g_object_unref(G_OBJECT(contour->point_pango));
984 	contour->point_pango = gtk_widget_create_pango_layout (widget, contour->point_str);
985 	if(contour->point_pango)
986 	{
987 		PangoRectangle logical_rect;
988 		pango_layout_set_justify(contour->point_pango,TRUE);
989 		pango_layout_set_alignment(contour->point_pango,PANGO_ALIGN_CENTER);
990 		pango_layout_set_alignment(contour->point_pango,PANGO_ALIGN_LEFT);
991 		pango_layout_set_markup(contour->point_pango, contour->point_str, -1);
992 		gchar fontName[100];
993 		PangoAttrList *attr_list;
994 		PangoFontDescription *font_desc = NULL;
995 		sprintf(fontName,"sans %d",2+contour->point_size*2);
996 		font_desc = pango_font_description_from_string (fontName);
997     		pango_layout_set_font_description (contour->point_pango, font_desc);
998 		pango_layout_context_changed(contour->point_pango);
999 		pango_layout_get_pixel_extents(contour->point_pango, NULL, &logical_rect);
1000     		pango_layout_get_size(contour->point_pango, &(contour->point_width), &(contour->point_height));
1001 		contour->point_width/=PANGO_SCALE;
1002 		contour->point_height/=PANGO_SCALE;
1003 		/* printf("%d %d\n",logical_rect.x,logical_rect.y);*/
1004 		contour->point_width =logical_rect.width;
1005 		contour->point_height =logical_rect.height;
1006 		pango_font_description_free (font_desc);
1007 		/* set color */
1008 		attr_list = pango_layout_get_attributes (contour->point_pango);
1009 		if (attr_list == NULL) attr_list = pango_attr_list_new ();
1010 		else pango_attr_list_ref (attr_list);
1011 		pango_attr_list_insert(attr_list,
1012 				pango_attr_foreground_new(
1013 					contour->point_color.red,
1014 					contour->point_color.green,
1015 					contour->point_color.blue)
1016 				);
1017 		pango_layout_set_attributes (contour->point_pango, attr_list);
1018 		pango_attr_list_unref (attr_list);
1019 	}
1020 }
1021 /**************************************************************/
getzMinzMax(GtkWidget * contoursplot,ContoursPlotData * data,gdouble * zmin,gdouble * zmax)1022 static void getzMinzMax(GtkWidget* contoursplot, ContoursPlotData* data, gdouble* zmin, gdouble* zmax)
1023 {
1024 	*zmin = 0;
1025 	*zmax = 0;
1026 	if(data)
1027 	{
1028 		*zmin=data->zmin;
1029 		*zmax=data->zmax;
1030 	}
1031 	if(contoursplot && GABEDIT_ContoursPLOT(contoursplot)->data_list)
1032 	{
1033 		gint ib = 0;
1034 		GList *current_node;
1035 		current_node=g_list_last(GABEDIT_ContoursPLOT(contoursplot)->data_list);
1036 		if(current_node)
1037 		{
1038 			ContoursPlotData* data = (ContoursPlotData*)current_node->data;
1039 			if(ib==0)
1040 			{
1041 				*zmin=data->zmin;
1042 				*zmax=data->zmax;
1043 			}
1044 			else
1045 			{
1046 				ib = 1;
1047 				if(*zmin>data->zmin) *zmin=data->zmin;
1048 				if(*zmax<data->zmax) *zmax=data->zmax;
1049 			}
1050 		}
1051 	}
1052 }
1053 /**************************************************************/
get_one_point(gdouble v1,gdouble v2,gdouble x1,gdouble y1,gdouble x2,gdouble y2,gdouble * x,gdouble * y)1054 static void get_one_point(gdouble v1, gdouble v2, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble* x, gdouble* y)
1055 {
1056 	gdouble u1 = x1;
1057 	gdouble u2 = x2;
1058 	if(v1==0) *x = u1;
1059 	else *x = u1 - v1 *(u2-u1)/(v2-v1);
1060 	u1 = y1;
1061 	u2 = y2;
1062 	if(v1==0) *y = u1;
1063 	else *y = u1 - v1 *(u2-u1)/(v2-v1);
1064 }
1065 /**************************************************************/
get_1r2(gdouble x1,gdouble y1,gdouble x2,gdouble y2)1066 static gdouble get_1r2(gdouble x1, gdouble y1, gdouble x2, gdouble y2)
1067 {
1068 	gdouble r2 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
1069 	if(r2<1e-14) return 1e14;
1070 	return 1/r2;
1071 }
1072 /**************************************************************/
get_contour_point(GtkWidget * contoursplot,ContoursPlotData * data,gdouble value)1073 ContourData get_contour_point(GtkWidget* contoursplot, ContoursPlotData *data, gdouble value)
1074 {
1075 	gint i;
1076 	gint j;
1077 	gint k;
1078 	gdouble v1;
1079 	gdouble v2;
1080 	gint ix=0,iy=0;
1081 	gint ix1=0,iy1=0;
1082 	gint ix2=0,iy2=0;
1083 	gint ix3=0,iy3=0;
1084 	gint ix4=0,iy4=0;
1085 	gdouble x1,x2,y1,y2,x,y;
1086 	gdouble dx, dy;
1087 	gdouble xmin,xmax,ymin,ymax;
1088 	gint xsize,ysize;
1089 	gdouble* zValues;
1090 	ContourData contour;
1091 	gint red = rand()%60000;
1092 	gint green = rand()%60000;
1093 	gint blue = rand()%60000;
1094 	gdouble color[3];
1095 
1096 	contour.value = value;
1097 	contour.size = 0;
1098 	contour.x = NULL;
1099 	contour.y = NULL;
1100 	contour.index = NULL;
1101 	xmin = data->xmin;
1102 	xmax = data->xmax;
1103 	ymin = data->ymin;
1104 	ymax = data->ymax;
1105 	xsize = data->xsize;
1106 	ysize = data->ysize;
1107 	dx = (xmax-xmin)/(xsize-1);
1108 	dy = (ymax-ymin)/(ysize-1);
1109 	zValues = data->zValues;
1110 
1111 	for( i = 0; i<xsize-1;i++)
1112 	{
1113 		for( j = 0; j<ysize-1;j++)
1114 		{
1115 			ix = i;
1116 			ix1 = ix2 = ix + 1;
1117 			ix4 = ix3 = ix;
1118 			iy = j;
1119 			iy1 = iy4 =  iy;
1120 			iy2 = iy3 = iy+1 ;
1121 
1122 			k = -1;
1123 
1124 			v1 = zValues[ix*ysize+iy]-value,
1125 			v2 = zValues[ix1*ysize+iy1]-value;
1126 			if( v1*v2 <=0 )
1127 			{
1128 				k++;
1129 				x1 = xmin+ix*dx;
1130 				y1 = ymin+iy*dy;
1131 				x2 = xmin+ix1*dx;
1132 				y2 = ymin+iy1*dy;
1133 				get_one_point(v1, v2, x1, y1, x2, y2, &x, &y);
1134 				contour.size++;
1135 				contour.x = g_realloc(contour.x,contour.size*sizeof(gdouble));
1136 				contour.y = g_realloc(contour.y,contour.size*sizeof(gdouble));
1137 				contour.index = g_realloc(contour.index,contour.size*sizeof(gint));
1138 				contour.x[contour.size-1]=x;
1139 				contour.y[contour.size-1]=y;
1140 				contour.index[contour.size-1]=i*ysize+j;
1141 
1142 			}
1143 			v1 = v2;
1144 			v2 = zValues[ix2*ysize+iy2]-value;
1145 			if( v1*v2 <=0 )
1146 			{
1147 				k++;
1148 				x1 = xmin+ix1*dx;
1149 				y1 = ymin+iy1*dy;
1150 				x2 = xmin+ix2*dx;
1151 				y2 = ymin+iy2*dy;
1152 				get_one_point(v1, v2, x1, y1, x2, y2, &x, &y);
1153 				contour.size++;
1154 				contour.x = g_realloc(contour.x,contour.size*sizeof(gdouble));
1155 				contour.y = g_realloc(contour.y,contour.size*sizeof(gdouble));
1156 				contour.index = g_realloc(contour.index,contour.size*sizeof(gint));
1157 				contour.x[contour.size-1]=x;
1158 				contour.y[contour.size-1]=y;
1159 				contour.index[contour.size-1]=i*ysize+j;
1160 			}
1161 			v1 = v2;
1162 			v2 = zValues[ix3*ysize+iy3]-value;
1163 			if( v1*v2 <=0 )
1164 			{
1165 				k++;
1166 				x1 = xmin+ix2*dx;
1167 				y1 = ymin+iy2*dy;
1168 				x2 = xmin+ix3*dx;
1169 				y2 = ymin+iy3*dy;
1170 				get_one_point(v1, v2, x1, y1, x2, y2, &x, &y);
1171 				contour.size++;
1172 				contour.x = g_realloc(contour.x,contour.size*sizeof(gdouble));
1173 				contour.y = g_realloc(contour.y,contour.size*sizeof(gdouble));
1174 				contour.index = g_realloc(contour.index,contour.size*sizeof(gint));
1175 				contour.x[contour.size-1]=x;
1176 				contour.y[contour.size-1]=y;
1177 				contour.index[contour.size-1]=i*ysize+j;
1178 			}
1179 			v1 = v2;
1180 			v2 = zValues[ix4*ysize+iy4]-value;
1181 
1182 			if( v1*v2 <=0 )
1183 			{
1184 				k++;
1185 				x1 = xmin+ix3*dx;
1186 				y1 = ymin+iy3*dy;
1187 				x2 = xmin+ix4*dx;
1188 				y2 = ymin+iy4*dy;
1189 				get_one_point(v1, v2, x1, y1, x2, y2, &x, &y);
1190 				contour.size++;
1191 				contour.x = g_realloc(contour.x,contour.size*sizeof(gdouble));
1192 				contour.y = g_realloc(contour.y,contour.size*sizeof(gdouble));
1193 				contour.index = g_realloc(contour.index,contour.size*sizeof(gint));
1194 				contour.x[contour.size-1]=x;
1195 				contour.y[contour.size-1]=y;
1196 				contour.index[contour.size-1]=i*ysize+j;
1197 			}
1198 		}
1199 	}
1200 	sprintf(contour.point_str,"+");
1201 	contour.point_pango = NULL;
1202 	contoursplot_build_points_contour(GABEDIT_ContoursPLOT(contoursplot), &contour);
1203 
1204 	contour.point_size = 0;
1205 	contour.line_width=2;
1206 	contour.point_color.red=red;
1207 	contour.point_color.green=green;
1208 	contour.point_color.blue=blue;
1209 
1210 	contour.line_color.red=green;
1211 	contour.line_color.green=red;
1212 	contour.line_color.blue=blue;
1213 	if(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap)
1214 	{
1215 		set_Color_From_colorMap(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap, color, value);
1216 		contour.line_color.red=(gushort)(color[0]*65535);
1217 		contour.line_color.green=(gushort)(color[1]*65535);
1218 		contour.line_color.blue=(gushort)(color[2]*65535);
1219 	}
1220 
1221 	contour.line_style=GDK_LINE_SOLID;
1222 	if(GABEDIT_ContoursPLOT(contoursplot)->dashed_negative_contours && value<0) contour.line_style = GDK_LINE_ON_OFF_DASH;
1223 
1224 	contour.label = g_malloc( (sizeof(gchar) * (GABEDIT_ContoursPLOT(contoursplot)->x_legends_digits+1)));
1225 	snprintf(contour.label, GABEDIT_ContoursPLOT(contoursplot)->x_legends_digits+1, "%lf", value);
1226 	contour.label[GABEDIT_ContoursPLOT(contoursplot)->x_legends_digits]='\0';
1227 	contour.xlabel = 0;
1228 	contour.ylabel = 0;
1229 	if(contour.size>0)
1230 	{
1231 		gint i = 0;
1232 		gdouble vmin = get_1r2(contour.x[i],contour.y[i],xmin,ymin)
1233 			       +get_1r2(contour.x[i],contour.y[i],xmin,ymax)
1234 			       +get_1r2(contour.x[i],contour.y[i],xmax,ymin)
1235 			       +get_1r2(contour.x[i],contour.y[i],xmax,ymax);
1236 
1237 		contour.xlabel = contour.x[0];
1238 		contour.ylabel = contour.y[0];
1239 		for(i=1;i<contour.size;i++)
1240 		{
1241 			gdouble v = get_1r2(contour.x[i],contour.y[i],xmin,ymin)
1242 			       +get_1r2(contour.x[i],contour.y[i],xmin,ymax)
1243 			       +get_1r2(contour.x[i],contour.y[i],xmax,ymin)
1244 			       +get_1r2(contour.x[i],contour.y[i],xmax,ymax);
1245 
1246 			if(v<vmin)
1247 			{
1248 				contour.xlabel = contour.x[i];
1249 				contour.ylabel = contour.y[i];
1250 				vmin = v;
1251 			}
1252 		}
1253 	}
1254 	return contour;
1255 
1256 }
1257 /****************************************************************************************/
set_label_one_contour(ContoursPlotData * data,gint n)1258 static void set_label_one_contour(ContoursPlotData* data, gint n)
1259 {
1260 	gint i;
1261 	gint j;
1262 	gdouble vmin = 0;
1263 	gdouble xmin, xmax, ymin, ymax;
1264 	gdouble dx, dy;
1265 	gint k;
1266 	gint N = 10;
1267 	if(!data) return;
1268 	if(data->contours[n].size<1) return;
1269 	data->contours[n].xlabel = data->contours[n].x[0];
1270 	data->contours[n].ylabel = data->contours[n].y[0];
1271 	xmin = data->xmin;
1272 	xmax = data->xmax;
1273 	ymin = data->ymin;
1274 	ymax = data->ymax;
1275 	dx = (xmax-xmin)/(N-1);
1276 	dy = (ymax-ymin)/(N-1);
1277 	i = 0;
1278 	vmin = 0;
1279 	for(k=0;k<N; k++)
1280 	{
1281 		gdouble x;
1282 		gdouble y;
1283 		x = xmin + dx*k;
1284 		y = ymin;
1285 		vmin += get_1r2(data->contours[n].x[i],data->contours[n].y[i],x,y);
1286 		y = ymax;
1287 		vmin += get_1r2(data->contours[n].x[i],data->contours[n].y[i],x,y);
1288 		x = xmin;
1289 		y = ymin + dy*k;
1290 		vmin += get_1r2(data->contours[n].x[i],data->contours[n].y[i],x,y);
1291 		x = xmax;
1292 		y = ymin + dy*k;
1293 		vmin += get_1r2(data->contours[n].x[i],data->contours[n].y[i],x,y);
1294 	}
1295 	for(j=0;j<n; j++)
1296 	{
1297 		vmin += get_1r2( data->contours[n].x[i],data->contours[n].y[i],
1298 				data->contours[j].xlabel,data->contours[j].ylabel);
1299 	}
1300 
1301 	data->contours[n].xlabel = data->contours[n].x[0];
1302 	data->contours[n].ylabel = data->contours[n].y[0];
1303 	for(i=1;i<data->contours[n].size;i++)
1304 	{
1305 		gdouble v = 0;
1306 		for(k=0;k<N; k++)
1307 		{
1308 			gdouble x;
1309 			gdouble y;
1310 			x = xmin + dx*k;
1311 			y = ymin;
1312 			v += get_1r2(data->contours[n].x[i],data->contours[n].y[i],x,y);
1313 			y = ymax;
1314 			v += get_1r2(data->contours[n].x[i],data->contours[n].y[i],x,y);
1315 			x = xmin;
1316 			y = ymin + dy*k;
1317 			v += get_1r2(data->contours[n].x[i],data->contours[n].y[i],x,y);
1318 			x = xmax;
1319 			y = ymin + dy*k;
1320 			v += get_1r2(data->contours[n].x[i],data->contours[n].y[i],x,y);
1321 		}
1322 		for(j=0;j<n; j++)
1323 			v += get_1r2( data->contours[n].x[i],data->contours[n].y[i],
1324 			data->contours[j].xlabel,data->contours[j].ylabel);
1325 
1326 		if(v<vmin)
1327 		{
1328 			data->contours[n].xlabel = data->contours[n].x[i];
1329 			data->contours[n].ylabel = data->contours[n].y[i];
1330 			vmin = v;
1331 		}
1332 	}
1333 }
1334 /****************************************************************************************/
reset_label_contours(GtkWidget * contoursplot,ContoursPlotData * data)1335 static void reset_label_contours(GtkWidget* contoursplot, ContoursPlotData* data)
1336 {
1337 
1338 	gint n;
1339 	if(!GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap) return;
1340 	if(data)
1341 	{
1342 		for(n=0;n<data->nContours; n++)
1343 			set_label_one_contour(data, n);
1344 	}
1345 	else
1346 	{
1347 		GList *current_node;
1348 		current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
1349 		for (; current_node!=NULL; current_node=current_node->next)
1350 		{
1351 			data=(ContoursPlotData*)current_node->data;
1352 			for(n=0;n<data->nContours; n++)
1353 				set_label_one_contour(data, n);
1354 		}
1355 	}
1356 }
1357 /**************************************************************/
free_one_contour(ContourData * contour)1358 static void free_one_contour(ContourData* contour)
1359 {
1360 	if(contour->x) g_free(contour->x);
1361 	if(contour->y) g_free(contour->y);
1362 	if(contour->index) g_free(contour->index);
1363 	if(contour->point_pango) g_object_unref(G_OBJECT(contour->point_pango));
1364 	contour->x = NULL;
1365 	contour->y = NULL;
1366 	contour->index = NULL;
1367 	contour->point_pango = NULL;
1368 }
1369 /**************************************************************/
add_one_contour(GtkWidget * contoursplot,ContoursPlotData * data,gdouble value)1370 static void add_one_contour(GtkWidget* contoursplot, ContoursPlotData *data, gdouble value)
1371 {
1372 	ContourData  contour;
1373 	if(!data) return;
1374 	contour = get_contour_point(contoursplot, data, value);
1375 	if(contour.size<1) return;
1376 	data->nContours++;
1377 	data->contours = g_realloc(data->contours,data->nContours*sizeof(ContourData));
1378 	data->contours[data->nContours-1] = contour;
1379 }
1380 /**********************************************/
delete_last_spaces(gchar * str)1381 static void delete_last_spaces(gchar* str)
1382 {
1383 	gchar *s;
1384 
1385 	if(str == NULL)
1386 		return;
1387 
1388 	if (!*str)
1389 		return;
1390 	for (s = str + strlen (str) - 1; s >= str && isspace ((guchar)*s); s--)
1391 		*s = '\0';
1392 }
1393 /**********************************************/
delete_first_spaces(gchar * str)1394 static void delete_first_spaces(gchar* str)
1395 {
1396 	gchar *start;
1397 	gint i;
1398 	gint lenSpace = 0;
1399 
1400 	if(str == NULL) return;
1401 	if (!*str) return;
1402 
1403 	for (start = str; *start && isspace (*start); start++)lenSpace++;
1404 
1405 	for(i=0;i<(gint)(strlen(str)-lenSpace);i++)
1406 		str[i] = str[i+lenSpace];
1407 	str[strlen(str)-lenSpace] = '\0';
1408 }
1409 /**********************************************/
1410 /*
1411 static void delete_all_spaces(gchar* str)
1412 {
1413 	gint i;
1414 	gint j;
1415 	gboolean Ok = FALSE;
1416 
1417 	delete_last_spaces(str);
1418 	delete_first_spaces(str);
1419 	while(!Ok)
1420 	{
1421 		Ok = TRUE;
1422 		for(i=0;i<(gint)strlen(str);i++)
1423 		{
1424 			if(isspace(str[i]))
1425 			{
1426 				Ok = FALSE;
1427 				for(j=i;j<(gint)strlen(str);j++)
1428 				{
1429 					str[j] = str[j+1];
1430 				}
1431 				break;
1432 			}
1433 		}
1434 	}
1435 }
1436 */
1437 /*************************************************************************************/
testascii(char c)1438 static gboolean testascii(char c)
1439 {
1440 	switch ( c )
1441 	{
1442 	case	'0':
1443 	case	'1':
1444 	case	'2':
1445 	case	'3':
1446 	case	'4':
1447 	case	'5':
1448 	case	'6':
1449 	case	'7':
1450 	case	'8':
1451 	case	'9':
1452 	case	'.':
1453 	case	'e':
1454 	case	'E':
1455 	case	'+':
1456 	case	'-':return TRUE;
1457 	}
1458 	return FALSE;
1459 }
1460 /*************************************************************************************/
this_is_a_real(gchar * t)1461 static gboolean this_is_a_real(gchar *t)
1462 {
1463 	gint i;
1464 	for(i=0;i<strlen(t);i++)
1465 		if(!testascii(t[i]) ) return FALSE;
1466 	if(t[0] =='e' || t[0] =='E' ) return FALSE;
1467 	return TRUE;
1468 
1469 }
1470 /****************************************************************************************/
delete_contours(GtkWidget * contoursplot,ContoursPlotData * data)1471 static void delete_contours(GtkWidget* contoursplot, ContoursPlotData* data)
1472 {
1473 
1474 	gint loop;
1475 	if(!GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap) return;
1476 	if(data)
1477 	{
1478 		for(loop=0;loop<data->nContours; loop++)
1479 			free_one_contour(&data->contours[loop]);
1480 		if(data->contours) g_free(data->contours);
1481 		data->nContours = 0;
1482 		data->contours = NULL;
1483 	}
1484 	else
1485 	{
1486 		GList *current_node;
1487 		current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
1488 		for (; current_node!=NULL; current_node=current_node->next)
1489 		{
1490 			data=(ContoursPlotData*)current_node->data;
1491 			for(loop=0;loop<data->nContours; loop++)
1492 				free_one_contour(&data->contours[loop]);
1493 			if(data->contours) g_free(data->contours);
1494 			data->nContours = 0;
1495 			data->contours = NULL;
1496 		}
1497 	}
1498 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
1499 }
1500 
1501 /********************************************************************************/
Message(gchar * message,gchar * title)1502 static void Message(gchar* message, gchar* title)
1503 {
1504 	GtkWidget* dialog = NULL;
1505 	if(!message) return;
1506 	if(!title) return;
1507 	if(strstr(title,"Error"))
1508 	dialog = gtk_message_dialog_new_with_markup (NULL,
1509                  GTK_DIALOG_DESTROY_WITH_PARENT,
1510 		GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
1511 	        "%s",
1512 		message);
1513 	else
1514 	dialog = gtk_message_dialog_new_with_markup (NULL,
1515                  GTK_DIALOG_DESTROY_WITH_PARENT,
1516 		GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
1517 			   "%s",
1518 		message);
1519 
1520 	if(dialog)
1521 	{
1522 		gtk_dialog_run (GTK_DIALOG (dialog));
1523 		gtk_widget_destroy (dialog);
1524 	}
1525 }
1526 /********************************************************************************/
get_a_float(GtkWidget * Entry,gdouble * value,gchar * errorMessage)1527 static gboolean get_a_float(GtkWidget* Entry,gdouble* value, gchar* errorMessage)
1528 {
1529 	G_CONST_RETURN gchar* temp;
1530 	gchar* t = NULL;
1531         temp	= gtk_entry_get_text(GTK_ENTRY(Entry));
1532 	if(temp&& strlen(temp)>0)
1533 	{
1534 		t = g_strdup(temp);
1535 		delete_first_spaces(t);
1536 		delete_last_spaces(t);
1537 	}
1538 	else
1539 	{
1540 		Message(errorMessage,"Error");
1541 		return FALSE;
1542 	}
1543 	if(t && !this_is_a_real(t))
1544 	{
1545 		Message(errorMessage,"Error");
1546 		g_free(t);
1547 		return FALSE;
1548 	}
1549 	if(t) g_free(t);
1550 	*value = atof(temp);
1551 	return TRUE;
1552 }
1553 /********************************************************************************/
add_widget_table(GtkWidget * Table,GtkWidget * wid,gushort line,gushort colonne)1554 static void add_widget_table(GtkWidget *Table,GtkWidget *wid,gushort line,gushort colonne)
1555 {
1556 
1557 	gtk_table_attach(GTK_TABLE(Table),wid,colonne,colonne+1,line,line+1,
1558                   (GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
1559                   (GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
1560                   3,3);
1561 
1562 }
1563 /********************************************************************************/
add_label_at_table(GtkWidget * Table,gchar * label,gushort line,gushort colonne,GtkJustification just)1564 static GtkWidget *add_label_at_table(GtkWidget *Table,gchar *label,gushort line,gushort colonne,GtkJustification just)
1565 {
1566 	GtkWidget *Label;
1567 	GtkWidget *hbox = gtk_hbox_new(0,FALSE);
1568 
1569 	Label = gtk_label_new (label);
1570    	gtk_label_set_justify(GTK_LABEL(Label),just);
1571 	if(just ==GTK_JUSTIFY_CENTER)
1572 		gtk_box_pack_start (GTK_BOX (hbox), Label, TRUE, TRUE, 0);
1573 	else
1574 		gtk_box_pack_start (GTK_BOX (hbox), Label, FALSE, FALSE, 0);
1575 
1576 	add_widget_table(Table,hbox,line,colonne);
1577 
1578 	return Label;
1579 }
1580 /********************************************************************************/
apply_contours(GtkWidget * window,gpointer data)1581 static void apply_contours(GtkWidget *window,gpointer data)
1582 {
1583 	GtkWidget* entryNumber =(GtkWidget*)g_object_get_data(G_OBJECT (window), "EntryNumber");
1584 	GtkWidget* entryMin =(GtkWidget*)g_object_get_data(G_OBJECT (window), "EntryMin");
1585 	GtkWidget* entryMax =(GtkWidget*)g_object_get_data(G_OBJECT (window), "EntryMax");
1586 	GtkWidget* linearButton =(GtkWidget*)g_object_get_data(G_OBJECT (window), "LinearButton");
1587 	GtkWidget* contoursplot = (GtkWidget* )g_object_get_data(G_OBJECT (window), "ContoursPlot");
1588 	G_CONST_RETURN gchar* temp;
1589 	gint i;
1590 	gint N;
1591 	gdouble min;
1592 	gdouble max;
1593 	gdouble* values = NULL;
1594 	gdouble step = 0;
1595 
1596         temp	= gtk_entry_get_text(GTK_ENTRY(entryNumber));
1597 	N = atoi(temp);
1598 	if(N<=0)
1599 	{
1600 		Message(_("Error : The number of points should be a positive integer. "),_("Error"));
1601 		return;
1602 	}
1603         if(!get_a_float(entryMin,&min,_("Error : The minimal value should be float.") )) return;
1604         if(!get_a_float(entryMax,&max,_("Error : The maximal value should be float."))) return;
1605 	if( max<=min)
1606 	{
1607 		Message(_("Error :  The minimal value should be smaller than the maximal value "),_("Error"));
1608 		return;
1609 	}
1610 
1611 	values = g_malloc(N*sizeof(gdouble));
1612 
1613 	if(GTK_TOGGLE_BUTTON (linearButton)->active)
1614 	{
1615 		step = (max-min)/(N-1);
1616 		for(i=0;i<N;i++) values[i] = min + i*step;
1617 	}
1618 	else
1619 	{
1620 		gdouble e = exp(1.0);
1621 		step = (1.0)/(N-1);
1622 		for(i=0;i<N;i++) values[i] = min+(max-min)*log(step*i*(e-1)+1);
1623 	}
1624 	/* Debug("Begin set_contours_values\n");*/
1625 	if(contoursplot && GABEDIT_ContoursPLOT(contoursplot)->data_list)
1626 	{
1627 		GList *current_node;
1628 		current_node=g_list_last(GABEDIT_ContoursPLOT(contoursplot)->data_list);
1629 		if(current_node)
1630 		{
1631 			ContoursPlotData* data = (ContoursPlotData*)current_node->data;
1632 			gint i;
1633 			for(i=0;i<N;i++)
1634 			{
1635 				add_one_contour(contoursplot, data, values[i]);
1636 			}
1637 		}
1638 	}
1639 	reset_label_contours(contoursplot, NULL);
1640 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
1641 	/* Debug("End set_contours_values\n");*/
1642 	if(values) g_free(values);
1643 
1644   	gtk_widget_destroy(window);
1645 }
1646 /********************************************************************************/
create_contours_frame(GtkWidget * contoursplot,GtkWidget * window,GtkWidget * vboxall,gchar * title,ContoursPlotData * data)1647 static GtkWidget *create_contours_frame(GtkWidget* contoursplot, GtkWidget *window, GtkWidget *vboxall,gchar* title, ContoursPlotData* data)
1648 {
1649 	GtkWidget *frame;
1650 	GtkWidget *LabelMin = NULL;
1651 	GtkWidget *LabelMax = NULL;
1652 	GtkWidget *vboxframe;
1653 	GtkWidget *hseparator;
1654 	GtkWidget *linearButton;
1655 	GtkWidget *logButton;
1656 	GtkWidget *entryNumber = NULL;
1657 	GtkWidget *entryMin = NULL;
1658 	GtkWidget *entryMax = NULL;
1659 	gushort i;
1660 	gushort j;
1661 	GtkWidget *Table;
1662 	gdouble min = 0;
1663 	gdouble max = 0;
1664 	gchar t[100];
1665 
1666 	getzMinzMax(contoursplot, data, &min, &max);
1667 	frame = gtk_frame_new (title);
1668 	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
1669 	gtk_container_add (GTK_CONTAINER (vboxall), frame);
1670 	gtk_widget_show (frame);
1671 
1672 	vboxframe=gtk_vbox_new(FALSE, 0);
1673 	gtk_container_add(GTK_CONTAINER(frame), vboxframe);
1674 	Table = gtk_table_new(5,3,FALSE);
1675 	gtk_container_add(GTK_CONTAINER(vboxframe),Table);
1676 
1677 	i = 0;
1678 	j = 0;
1679 	add_label_at_table(Table,_(" Numbre of contours "),i,j,GTK_JUSTIFY_LEFT);
1680 	j++;
1681 	add_label_at_table(Table," : ",i,j,GTK_JUSTIFY_LEFT);
1682 	j++;
1683 	entryNumber = gtk_entry_new ();
1684 	add_widget_table(Table,entryNumber,i,j);
1685 	gtk_entry_set_text(GTK_ENTRY(entryNumber),"10");
1686 
1687 	i = 1;
1688 	j = 0;
1689 	LabelMin = add_label_at_table(Table,_(" Min iso-value "),i,j,GTK_JUSTIFY_LEFT);
1690 	j++;
1691 	add_label_at_table(Table," : ",i,j,GTK_JUSTIFY_LEFT);
1692 	j++;
1693 	entryMin = gtk_entry_new ();
1694 	add_widget_table(Table,entryMin,i,j);
1695 	sprintf(t,"%f",min);
1696 	gtk_entry_set_text(GTK_ENTRY(entryMin),t);
1697 
1698 	i = 2;
1699 	j = 0;
1700 	LabelMax = add_label_at_table(Table,_(" Max iso-value "),i,j,GTK_JUSTIFY_LEFT);
1701 	j++;
1702 	add_label_at_table(Table," : ",i,j,GTK_JUSTIFY_LEFT);
1703 	j++;
1704 	entryMax = gtk_entry_new ();
1705 	add_widget_table(Table,entryMax,i,j);
1706 	sprintf(t,"%f",max);
1707 	gtk_entry_set_text(GTK_ENTRY(entryMax),t);
1708 
1709 
1710 	i=3;
1711 	hseparator = gtk_hseparator_new ();
1712 	gtk_table_attach(GTK_TABLE(Table),hseparator,0,3,i,i+1,
1713                   (GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
1714                   (GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
1715                   3,3);
1716 
1717 	i=5;
1718 	linearButton = gtk_radio_button_new_with_label( NULL,_("Linear scale"));
1719 	add_widget_table(Table, linearButton,i,0);
1720 	logButton = gtk_radio_button_new_with_label( gtk_radio_button_get_group (GTK_RADIO_BUTTON (linearButton)), _("logarithmic scale"));
1721 	gtk_table_attach(GTK_TABLE(Table), logButton,1,3,i,i+1,
1722 		  (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
1723 		  (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
1724 		  3,3);
1725 
1726 	g_object_set_data(G_OBJECT (window), "EntryNumber",entryNumber);
1727 	g_object_set_data(G_OBJECT (window), "EntryMin",entryMin);
1728 	g_object_set_data(G_OBJECT (window), "EntryMax",entryMax);
1729 	g_object_set_data(G_OBJECT (window), "LinearButton",linearButton);
1730 	g_object_set_data(G_OBJECT (window), "LogButton",logButton);
1731 
1732 	gtk_widget_show_all(frame);
1733 
1734   	return frame;
1735 }
1736 
1737 /**************************************************************/
create_contours(GtkWidget * contoursplot,ContoursPlotData * data)1738 static void create_contours(GtkWidget* contoursplot, ContoursPlotData* data)
1739 {
1740 	GtkWidget *window;
1741 	GtkWidget *frame;
1742 	GtkWidget *hbox;
1743 	GtkWidget *vboxall;
1744 	GtkWidget *vboxwin;
1745 	GtkWidget *button;
1746 
1747   	g_return_if_fail (contoursplot != NULL);
1748   	g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
1749 	if(GABEDIT_ContoursPLOT(contoursplot)->data_list == NULL)
1750 	{
1751 		Message(_("No data available :\n You should read a file"),_("Error"));
1752 		return;
1753 	}
1754   	g_return_if_fail (GABEDIT_ContoursPLOT(contoursplot)->data_list != NULL);
1755 
1756 	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1757 	gtk_window_set_title(GTK_WINDOW(window),_("Create contours"));
1758 	gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
1759 	gtk_container_set_border_width (GTK_CONTAINER (window), 5);
1760 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
1761 
1762 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
1763 
1764 	vboxall=gtk_vbox_new(FALSE, 0);
1765 	gtk_container_add (GTK_CONTAINER (window), vboxall);
1766 	vboxwin = vboxall;
1767 
1768 	frame = create_contours_frame(contoursplot, window,vboxall,_("Contours"), data);
1769 	g_object_set_data(G_OBJECT (window), "ContoursPlot",contoursplot);
1770 
1771 	/* buttons box */
1772 	hbox=gtk_hbox_new(FALSE, 0);
1773 	gtk_box_pack_start(GTK_BOX(vboxwin), hbox, TRUE, FALSE, 2);
1774 	gtk_widget_realize(window);
1775 
1776 	button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
1777 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1778 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
1779 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)gtk_widget_destroy,GTK_OBJECT(window));
1780 	gtk_widget_show (button);
1781 
1782 	button = gtk_button_new_from_stock(GTK_STOCK_OK);
1783 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
1784 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1785 	gtk_widget_grab_default(button);
1786 	gtk_widget_show (button);
1787 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)apply_contours,GTK_OBJECT(window));
1788 
1789 	/* Show all */
1790 	gtk_widget_show_all (window);
1791 }
1792 /************************************************************************************************************/
reset_color_map_min_max(GtkWidget * contoursplot,gdouble min,gdouble max)1793 static void reset_color_map_min_max(GtkWidget* contoursplot,gdouble min, gdouble max)
1794 {
1795 	ColorMap* newColorMap = NULL;
1796 
1797 	newColorMap = new_colorMap_min_max(min, max, GABEDIT_ContoursPLOT(contoursplot)->colorsMap.type,
1798 			GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colors);
1799 	colormap_free(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap);
1800 	g_free(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap);
1801 	GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap = newColorMap;
1802 	contoursplot_build_colormap_legends(GABEDIT_ContoursPLOT(contoursplot));
1803 }
1804 /************************************************************************************************************/
reset_color_map(GtkWidget * contoursplot,ContoursPlotData * data)1805 static void reset_color_map(GtkWidget* contoursplot, ContoursPlotData *data)
1806 {
1807 	if(!data && GABEDIT_ContoursPLOT(contoursplot)->data_list)
1808 	{
1809 		GList *current_node;
1810 		current_node=g_list_last(GABEDIT_ContoursPLOT(contoursplot)->data_list);
1811 		if(current_node) data = (ContoursPlotData*)current_node->data;
1812 	}
1813 	if(!data) return;
1814 	reset_color_map_min_max(contoursplot, data->zmin, data->zmax);
1815 }
1816 /********************************************************************************/
add_new_data(GtkWidget * contoursplot,gint xsize,gdouble xmin,gdouble xmax,gint ysize,gdouble ymin,gdouble ymax,gdouble * zValues)1817 static void add_new_data(GtkWidget* contoursplot,
1818 		gint xsize, gdouble xmin, gdouble xmax,
1819 		gint ysize, gdouble ymin, gdouble ymax,
1820 		gdouble* zValues)
1821 {
1822 	if(xsize>0 && ysize>0)
1823 	{
1824 		gint loop;
1825 		ContoursPlotData *data = g_malloc(sizeof(ContoursPlotData));
1826 		data->xsize=xsize;
1827 		data->xmin=xmin;
1828 		data->xmax=xmax;
1829 		data->ysize=xsize;
1830 		data->ymin=ymin;
1831 		data->ymax=ymax;
1832 		data->nContours=0;
1833 		data->contours=NULL;
1834 
1835 		data->zValues = g_malloc(xsize*ysize*sizeof(gdouble));
1836 
1837 		data->zmin=zValues[0];
1838 		data->zmax=zValues[0];
1839 		for(loop = 0; loop<data->xsize*data->ysize;loop++)
1840 		{
1841 			data->zValues[loop] = zValues[loop];
1842 			if(data->zmin>zValues[loop]) data->zmin=zValues[loop];
1843 			if(data->zmax<zValues[loop]) data->zmax=zValues[loop];
1844 		}
1845 
1846 		gabedit_contoursplot_add_data (GABEDIT_ContoursPLOT(contoursplot), data);
1847 		gabedit_contoursplot_set_autorange(GABEDIT_ContoursPLOT(contoursplot), NULL);
1848 		reset_color_map(contoursplot, data);
1849 	}
1850 }
1851 /****************************************************************************************/
set_object_text_pixels(GabeditContoursPlot * contoursplot,ContoursPlotObjectText * objectText)1852 static void set_object_text_pixels(GabeditContoursPlot *contoursplot, ContoursPlotObjectText* objectText)
1853 {
1854 	if(!objectText) return;
1855 	value2pixel(contoursplot, objectText->x,objectText->y, &objectText->xi, &objectText->yi);
1856 	objectText->yi=contoursplot->plotting_rect.height-objectText->yi;
1857 	pango_layout_get_size(objectText->pango, &objectText->width, &objectText->height);
1858 	objectText->width/=PANGO_SCALE;
1859 	objectText->height/=PANGO_SCALE;
1860 	/* objectText->yi -= objectText->height/2;*/
1861 	objectText->xi += contoursplot->plotting_rect.x;
1862 	objectText->yi += contoursplot->plotting_rect.y;
1863 }
1864 /****************************************************************************************/
get_pango_str(GabeditContoursPlot * contoursplot,G_CONST_RETURN gchar * txt)1865 static PangoLayout* get_pango_str(GabeditContoursPlot *contoursplot, G_CONST_RETURN gchar* txt)
1866 {
1867 	gchar *str = NULL;
1868 	GdkGCValues values;
1869 	GdkColormap *colormap;
1870 	GdkColor color;
1871 	gchar* rgb = NULL;
1872 	PangoLayout* pango;
1873 
1874 	if(!txt) return NULL;
1875 
1876 	pango = gtk_widget_create_pango_layout (GTK_WIDGET(contoursplot), txt);
1877 	pango_layout_set_alignment(pango,PANGO_ALIGN_LEFT);
1878 
1879 	gdk_gc_get_values(contoursplot->fore_gc, &values);
1880    	colormap  = gdk_window_get_colormap(GTK_WIDGET(contoursplot)->window);
1881         gdk_colormap_query_color(colormap, values.foreground.pixel,&color);
1882 	rgb = g_strdup_printf("#%02x%02x%02x", color.red >> 8, color.green >> 8, color.blue >> 8);
1883 	str = g_strconcat("<span foreground='", rgb, "'>",txt, "</span>", NULL);
1884 	pango_layout_set_markup(pango, str, -1);
1885 	g_free(str);
1886 	return pango;
1887 }
1888 /****************************************************************************************/
set_object_text_pango(GabeditContoursPlot * contoursplot,ContoursPlotObjectText * objectText)1889 static void set_object_text_pango(GabeditContoursPlot *contoursplot, ContoursPlotObjectText* objectText)
1890 {
1891 	if(!objectText) return;
1892   	objectText->pango = get_pango_str(contoursplot, objectText->str);
1893 }
1894 /****************************************************************************************/
set_object_text(GabeditContoursPlot * contoursplot,ContoursPlotObjectText * objectText,gdouble x,gdouble y,gdouble angle,G_CONST_RETURN gchar * str)1895 static void set_object_text(GabeditContoursPlot *contoursplot, ContoursPlotObjectText* objectText, gdouble x, gdouble y, gdouble angle, G_CONST_RETURN gchar* str)
1896 {
1897 	if(!str) return;
1898 	objectText->x = x;
1899 	objectText->y = y;
1900 	objectText->angle = angle;
1901 	objectText->str = g_strdup(str);
1902 	set_object_text_pango(contoursplot, objectText);
1903 	set_object_text_pixels(contoursplot, objectText);
1904 }
1905 /****************************************************************************************/
add_object_text(GabeditContoursPlot * contoursplot,gdouble x,gdouble y,gdouble angle,G_CONST_RETURN gchar * str)1906 static void add_object_text(GabeditContoursPlot *contoursplot, gdouble x, gdouble y, gdouble angle, G_CONST_RETURN gchar* str)
1907 {
1908 	gint i;
1909 	if(!str) return;
1910 	contoursplot->nObjectsText++;
1911 	if(contoursplot->nObjectsText==1) contoursplot->objectsText = g_malloc(sizeof(ContoursPlotObjectText));
1912 	else contoursplot->objectsText = g_realloc(contoursplot->objectsText,contoursplot->nObjectsText*sizeof(ContoursPlotObjectText));
1913 	i = contoursplot->nObjectsText-1;
1914 	set_object_text(contoursplot, &contoursplot->objectsText[i],  x,  y, angle, str);
1915 }
1916 /****************************************************************************************/
reset_object_text_pixels(GabeditContoursPlot * contoursplot)1917 static void reset_object_text_pixels(GabeditContoursPlot *contoursplot)
1918 {
1919 	gint i;
1920 	if(!contoursplot) return;
1921 	for(i=0;i<contoursplot->nObjectsText;i++)
1922 		set_object_text_pixels(contoursplot, &contoursplot->objectsText[i]);
1923 }
1924 /****************************************************************************************/
reset_object_text_pango(GabeditContoursPlot * contoursplot)1925 static void reset_object_text_pango(GabeditContoursPlot *contoursplot)
1926 {
1927 	gint i;
1928 	if(!contoursplot) return;
1929 	for(i=0;i<contoursplot->nObjectsText;i++)
1930 		set_object_text_pango(contoursplot, &contoursplot->objectsText[i]);
1931 }
1932 /****************************************************************************************/
get_object_text_num(GabeditContoursPlot * contoursplot,gint xi,gint yi)1933 static gint get_object_text_num(GabeditContoursPlot *contoursplot, gint xi, gint yi)
1934 {
1935 	gint i;
1936 	gint x,y;
1937 	if(!contoursplot) return -1;
1938 	for(i=0;i<contoursplot->nObjectsText;i++)
1939 	{
1940 		gdouble cosa = cos(contoursplot->objectsText[i].angle);
1941 		gdouble sina = sin(contoursplot->objectsText[i].angle);
1942 		gdouble xx = xi-contoursplot->objectsText[i].xi;
1943 		gdouble yy = yi-contoursplot->objectsText[i].yi;
1944 		x = contoursplot->objectsText[i].xi+xx*cosa-yy*sina;
1945 		y = contoursplot->objectsText[i].yi+xx*sina+yy*cosa;
1946 		if(x>=contoursplot->objectsText[i].xi && y>=contoursplot->objectsText[i].yi
1947 		&& x<=contoursplot->objectsText[i].xi+contoursplot->objectsText[i].width
1948 		&& y<=contoursplot->objectsText[i].yi+contoursplot->objectsText[i].height)
1949 			return i;
1950 	}
1951 	return -1;
1952 }
1953 /****************************************************************************************/
delete_object_text(GtkWidget * widget,gint i)1954 static void delete_object_text(GtkWidget *widget, gint i)
1955 {
1956 	gint j;
1957 	GabeditContoursPlot *contoursplot = NULL;
1958 	if(!widget) return;
1959 	if(!GTK_IS_WIDGET(widget)) return;
1960 	contoursplot = GABEDIT_ContoursPLOT(widget);
1961 	if(i<0||i>=contoursplot->nObjectsText) return;
1962 	if(contoursplot->objectsText[i].str) g_free(contoursplot->objectsText[i].str);
1963 	if(contoursplot->objectsText[i].pango) g_object_unref(G_OBJECT(contoursplot->objectsText[i].pango));
1964 	for(j=i;j<contoursplot->nObjectsText-1;j++)
1965 		contoursplot->objectsText[j] = contoursplot->objectsText[j+1];
1966 	contoursplot->nObjectsText--;
1967 	if(contoursplot->nObjectsText<1)
1968 	{
1969 		contoursplot->nObjectsText = 0;
1970 		if(contoursplot->objectsText) g_free(contoursplot->objectsText);
1971 		contoursplot->objectsText = NULL;
1972 	}
1973 	else
1974 	{
1975 		contoursplot->objectsText = g_realloc(contoursplot->objectsText,contoursplot->nObjectsText*sizeof(ContoursPlotObjectText));
1976 	}
1977 
1978 }
1979 /****************************************************************************************/
delete_objects_text(GtkWidget * widget)1980 static void delete_objects_text(GtkWidget *widget)
1981 {
1982 	GabeditContoursPlot *contoursplot = NULL;
1983 	gint i;
1984 	if(!widget) return;
1985 	if(!GTK_IS_WIDGET(widget)) return;
1986 	contoursplot = GABEDIT_ContoursPLOT(widget);
1987 	for(i=0;i<contoursplot->nObjectsText;i++)
1988 	{
1989 		if(contoursplot->objectsText[i].str) g_free(contoursplot->objectsText[i].str);
1990 		if(contoursplot->objectsText[i].pango) g_object_unref(G_OBJECT(contoursplot->objectsText[i].pango));
1991 	}
1992 	contoursplot->nObjectsText = 0;
1993 	if(contoursplot->objectsText) g_free(contoursplot->objectsText);
1994 	contoursplot->objectsText = NULL;
1995 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
1996 }
1997 /********************************************************************************/
activate_entry_object_text(GtkWidget * entry,gpointer user_data)1998 static void activate_entry_object_text(GtkWidget *entry, gpointer user_data)
1999 {
2000 	G_CONST_RETURN gchar* tlabel;
2001 	G_CONST_RETURN gchar* tangle;
2002 	GtkWidget* contoursplot = NULL;
2003 	GtkWidget* window = NULL;
2004 	GtkWidget* entry_label = NULL;
2005 	GtkWidget* entry_angle = NULL;
2006 	ContoursPlotObjectText* objectText = NULL;
2007 
2008 
2009 	if(!entry) return;
2010 	if(!GTK_IS_WIDGET(entry)) return;
2011 	if(!user_data || !G_IS_OBJECT(user_data)) return;
2012 
2013 	contoursplot = GTK_WIDGET(user_data);
2014 	entry_label = g_object_get_data(G_OBJECT(entry),"EntryLabel");
2015 	entry_angle = g_object_get_data(G_OBJECT(entry),"EntryAngle");
2016 
2017 	if(!GTK_IS_WIDGET(entry_label)) return;
2018 	if(!GTK_IS_WIDGET(entry_angle)) return;
2019 
2020 	tlabel= gtk_entry_get_text(GTK_ENTRY(entry_label));
2021 	tangle= gtk_entry_get_text(GTK_ENTRY(entry_angle));
2022 	window = g_object_get_data(G_OBJECT(entry),"Window");
2023 	objectText = g_object_get_data(G_OBJECT(entry),"ObjectText");
2024 	/* t is destroyed with window */
2025 	if(!objectText)
2026 	{
2027 		if(window)gtk_widget_destroy(window);
2028 		return;
2029 	}
2030 	if(!objectText->str)
2031 	{
2032 		gdouble angle = 0;
2033 		if(tangle && strlen(tangle)>0) angle = atof(tangle)/180.0*M_PI;
2034 		add_object_text(GABEDIT_ContoursPLOT(contoursplot), objectText->x, objectText->y, angle, tlabel);
2035 		g_free(objectText);
2036 	}
2037 	else
2038 	{
2039 		gdouble angle = 0;
2040 		if(tangle && strlen(tangle)>0) angle = atof(tangle)/180.0*M_PI;
2041 		if(objectText->str) g_free(objectText->str);
2042 		if(objectText->pango) g_object_unref(G_OBJECT(objectText->pango));
2043 		set_object_text(GABEDIT_ContoursPLOT(contoursplot), objectText,  objectText->x, objectText->y, angle, tlabel);
2044 	}
2045 	if(window)gtk_widget_destroy(window);
2046 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
2047 }
2048 /****************************************************************************************/
add_set_object_text_dialog(GtkWidget * contoursplot,gint i,gdouble x,gdouble y)2049 static void add_set_object_text_dialog(GtkWidget* contoursplot, gint i, gdouble x, gdouble y)
2050 {
2051 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2052 	GtkWidget* parentWindow = NULL;
2053 	GtkWidget* frame = NULL;
2054 	GtkWidget* hbox = NULL;
2055 	GtkWidget* vbox_frame = NULL;
2056 	GtkWidget* label = NULL;
2057 	GtkWidget* entry_label = NULL;
2058 	GtkWidget* entry_angle = NULL;
2059 	ContoursPlotObjectText* objectText = NULL;
2060 
2061 	if(i>-1 && i<GABEDIT_ContoursPLOT(contoursplot)->nObjectsText)
2062 	{
2063 		objectText = &GABEDIT_ContoursPLOT(contoursplot)->objectsText[i];
2064 	}
2065 	else
2066 	{
2067 		objectText = g_malloc(sizeof(ContoursPlotObjectText));
2068 		objectText->x = x;
2069 		objectText->y = y;
2070 		objectText->str = NULL;
2071 		objectText->pango = NULL;
2072 	}
2073 
2074 	gtk_window_set_title (GTK_WINDOW (window), _("Set label"));
2075 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2076 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
2077 
2078 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
2079 
2080 	hbox=gtk_hbox_new(FALSE, 0);
2081 	gtk_container_add(GTK_CONTAINER(window), hbox);
2082 	gtk_widget_show(hbox);
2083 
2084 	frame=gtk_frame_new(NULL);
2085 	gtk_container_add(GTK_CONTAINER(hbox), frame);
2086 	gtk_widget_show(frame);
2087 
2088 	vbox_frame=gtk_vbox_new(FALSE, 0);
2089 	gtk_container_add(GTK_CONTAINER(frame), vbox_frame);
2090 	gtk_widget_show(vbox_frame);
2091 
2092 	hbox=gtk_hbox_new(FALSE, 0);
2093 	gtk_box_pack_start(GTK_BOX(vbox_frame), hbox, FALSE, FALSE, 2);
2094 	gtk_widget_show(hbox);
2095 
2096 	label=gtk_label_new(_("Label : "));
2097 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
2098 	gtk_widget_show(label);
2099 
2100 	entry_label = gtk_entry_new();
2101 	/* gtk_widget_set_size_request(entry_label,100,-1);*/
2102 	if(i>-1 && i<GABEDIT_ContoursPLOT(contoursplot)->nObjectsText)
2103 	{
2104 		gtk_entry_set_text(GTK_ENTRY(entry_label),GABEDIT_ContoursPLOT(contoursplot)->objectsText[i].str);
2105 	}
2106 	else
2107 		gtk_entry_set_text(GTK_ENTRY(entry_label),"<span foreground='blue' font_desc='20'>Blue text</span> is <i>cool</i>!");
2108 	gtk_box_pack_start(GTK_BOX(hbox), entry_label, TRUE, TRUE, 2);
2109 	gtk_widget_show(entry_label);
2110 
2111 	g_object_set_data(G_OBJECT(entry_label),"ObjectText", objectText);
2112 
2113 	label=gtk_label_new(
2114 			_(
2115 			"You can use the Pango Text Attribute Markup Language\n"
2116 			"Example : <span foreground='blue' font_desc='Sans 20'>Blue text</span> is <i>cool</i>!\n"
2117 			"\nFor insert a special character : control shift u + code UTF8\n"
2118 			"Examples : \n"
2119 			" control shift u + 03B1 for alpha (greek)\n"
2120 			" control shift u + 03B2 for beta (greek)\n"
2121 			" control shift u + 03A3 for cap Sigma (greek)\n"
2122 			" See http://www.utf8-chartable.de\n"
2123 			)
2124 			);
2125 	gtk_widget_show(label);
2126 	gtk_box_pack_start(GTK_BOX(vbox_frame), label, FALSE, FALSE, 2);
2127 
2128 
2129 	g_object_set_data(G_OBJECT(entry_label),"Window", window);
2130 	g_signal_connect (G_OBJECT (entry_label), "activate", (GCallback)activate_entry_object_text, contoursplot);
2131 
2132 	hbox=gtk_hbox_new(FALSE, 0);
2133 	gtk_box_pack_start(GTK_BOX(vbox_frame), hbox, FALSE, FALSE, 2);
2134 	gtk_widget_show(hbox);
2135 
2136 	label=gtk_label_new(_("Angle : "));
2137 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
2138 	gtk_widget_show(label);
2139 
2140 	entry_angle = gtk_entry_new();
2141 	if(i>-1 && i<GABEDIT_ContoursPLOT(contoursplot)->nObjectsText)
2142 	{
2143 		gchar* tmp = g_strdup_printf("%f", GABEDIT_ContoursPLOT(contoursplot)->objectsText[i].angle/M_PI*180.0);
2144 		gtk_entry_set_text(GTK_ENTRY(entry_angle),tmp);
2145 		g_free(tmp);
2146 	}
2147 	else gtk_entry_set_text(GTK_ENTRY(entry_angle),"0.0");
2148 	gtk_box_pack_start(GTK_BOX(hbox), entry_angle, TRUE, TRUE, 2);
2149 	gtk_widget_show(entry_angle);
2150 
2151 	g_object_set_data(G_OBJECT(entry_angle),"ObjectText", objectText);
2152 	g_object_set_data(G_OBJECT(entry_angle),"Window", window);
2153 	g_object_set_data(G_OBJECT(entry_angle),"EntryLabel", entry_label);
2154 	g_object_set_data(G_OBJECT(entry_angle),"EntryAngle", entry_angle);
2155 	g_object_set_data(G_OBJECT(entry_label),"EntryLabel", entry_label);
2156 	g_object_set_data(G_OBJECT(entry_label),"EntryAngle", entry_angle);
2157 	g_signal_connect (G_OBJECT (entry_angle), "activate", (GCallback)activate_entry_object_text, contoursplot);
2158 
2159 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
2160 	if(parentWindow)
2161 	{
2162 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
2163 	}
2164 	gtk_widget_show(window);
2165 }
2166 /****************************************************************************************/
begin_insert_objects_text(GtkWidget * widget)2167 static void begin_insert_objects_text(GtkWidget *widget)
2168 {
2169 	if(!widget) return;
2170 	if(!GTK_IS_WIDGET(widget)) return;
2171 	GABEDIT_ContoursPLOT(widget)->t_key_pressed = TRUE;
2172 }
2173 /****************************************************************************************/
set_object_line_pixels(GabeditContoursPlot * contoursplot,ContoursPlotObjectLine * objectLine)2174 static void set_object_line_pixels(GabeditContoursPlot *contoursplot, ContoursPlotObjectLine* objectLine)
2175 {
2176 	if(!objectLine) return;
2177 	value2pixel(contoursplot, objectLine->x1,objectLine->y1, &objectLine->x1i, &objectLine->y1i);
2178 	objectLine->y1i=contoursplot->plotting_rect.height-objectLine->y1i;
2179 	objectLine->x1i += contoursplot->plotting_rect.x;
2180 	objectLine->y1i += contoursplot->plotting_rect.y;
2181 	value2pixel(contoursplot, objectLine->x2,objectLine->y2, &objectLine->x2i, &objectLine->y2i);
2182 	objectLine->y2i=contoursplot->plotting_rect.height-objectLine->y2i;
2183 	objectLine->x2i += contoursplot->plotting_rect.x;
2184 	objectLine->y2i += contoursplot->plotting_rect.y;
2185 }
2186 /****************************************************************************************/
set_object_line(GabeditContoursPlot * contoursplot,ContoursPlotObjectLine * objectLine,gdouble x1,gdouble y1,gdouble x2,gdouble y2,gint width,gint arrow_size,GdkColor color,GdkLineStyle style)2187 static void set_object_line(GabeditContoursPlot *contoursplot, ContoursPlotObjectLine* objectLine,
2188 		gdouble x1, gdouble y1,
2189 		gdouble x2, gdouble y2,
2190   		gint width,
2191   		gint arrow_size,
2192   		GdkColor color,
2193   		GdkLineStyle style
2194 		)
2195 {
2196 	if(!objectLine) return;
2197 	objectLine->x1 = x1;
2198 	objectLine->y1 = y1;
2199 	objectLine->x2 = x2;
2200 	objectLine->y2 = y2;
2201 	objectLine->width = width;
2202 	objectLine->arrow_size = arrow_size;
2203 	objectLine->color = color;
2204 	objectLine->style = style;
2205 	set_object_line_pixels(contoursplot, objectLine);
2206 }
2207 /****************************************************************************************/
add_object_line(GabeditContoursPlot * contoursplot,gdouble x1,gdouble y1,gdouble x2,gdouble y2)2208 static void add_object_line(GabeditContoursPlot *contoursplot,
2209 		gdouble x1, gdouble y1,
2210 		gdouble x2, gdouble y2
2211 		)
2212 {
2213   	gint width = 1;
2214   	gint arrow_size = 0;
2215   	GdkColor color;
2216   	GdkLineStyle style = GDK_LINE_SOLID;
2217 	gint i;
2218 	contoursplot->nObjectsLine++;
2219 	if(contoursplot->nObjectsLine==1) contoursplot->objectsLine = g_malloc(sizeof(ContoursPlotObjectLine));
2220 	else contoursplot->objectsLine = g_realloc(contoursplot->objectsLine,contoursplot->nObjectsLine*sizeof(ContoursPlotObjectLine));
2221 	i = contoursplot->nObjectsLine-1;
2222 
2223 	if(contoursplot->nObjectsLine==1)
2224 	{
2225 		GdkGCValues values;
2226 		GdkColormap *colormap;
2227 		gdk_gc_get_values(contoursplot->lines_gc, &values);
2228    		colormap  = gdk_window_get_colormap(GTK_WIDGET(contoursplot)->window);
2229         	gdk_colormap_query_color(colormap, values.foreground.pixel,&color);
2230 		style = values.line_style;
2231 		width = values.line_width;
2232 	}
2233 	else
2234 	{
2235 		color = contoursplot->objectsLine[contoursplot->nObjectsLine-2].color;
2236 		style = contoursplot->objectsLine[contoursplot->nObjectsLine-2].style;
2237 		width = contoursplot->objectsLine[contoursplot->nObjectsLine-2].width;
2238 		arrow_size = contoursplot->objectsLine[contoursplot->nObjectsLine-2].arrow_size;
2239 	}
2240 
2241 	set_object_line(contoursplot, &contoursplot->objectsLine[i],  x1,  y1, x2, y2,
2242 			width,
2243 			arrow_size,
2244 			color,
2245 			style);
2246 }
2247 /****************************************************************************************/
reset_object_line_pixels(GabeditContoursPlot * contoursplot)2248 static void reset_object_line_pixels(GabeditContoursPlot *contoursplot)
2249 {
2250 	gint i;
2251 	if(!contoursplot) return;
2252 	for(i=0;i<contoursplot->nObjectsLine;i++)
2253 		set_object_line_pixels(contoursplot, &contoursplot->objectsLine[i]);
2254 }
2255 /****************************************************************************************/
get_object_line_num(GabeditContoursPlot * contoursplot,gint xi,gint yi)2256 static gint get_object_line_num(GabeditContoursPlot *contoursplot, gint xi, gint yi)
2257 {
2258 	gint i;
2259 	if(!contoursplot) return -1;
2260 	for(i=0;i<contoursplot->nObjectsLine;i++)
2261 	{
2262 		gint d = get_distance_M_AB(contoursplot,xi,yi,
2263 				contoursplot->objectsLine[i].x1i,contoursplot->objectsLine[i].y1i,
2264 				contoursplot->objectsLine[i].x2i,contoursplot->objectsLine[i].y2i);
2265 		if(d<5 || d<contoursplot->objectsLine[i].width) return i;
2266 	}
2267 	return -1;
2268 }
2269 /****************************************************************************************/
delete_object_line(GtkWidget * widget,gint i)2270 static void delete_object_line(GtkWidget *widget, gint i)
2271 {
2272 	gint j;
2273 	GabeditContoursPlot *contoursplot = NULL;
2274 	if(!widget) return;
2275 	if(!GTK_IS_WIDGET(widget)) return;
2276 	contoursplot = GABEDIT_ContoursPLOT(widget);
2277 	if(i<0||i>=contoursplot->nObjectsLine) return;
2278 	for(j=i;j<contoursplot->nObjectsLine-1;j++)
2279 		contoursplot->objectsLine[j] = contoursplot->objectsLine[j+1];
2280 	contoursplot->nObjectsLine--;
2281 	if(contoursplot->nObjectsLine<1)
2282 	{
2283 		contoursplot->nObjectsLine = 0;
2284 		if(contoursplot->objectsLine) g_free(contoursplot->objectsLine);
2285 		contoursplot->objectsLine = NULL;
2286 	}
2287 	else
2288 	{
2289 		contoursplot->objectsLine = g_realloc(contoursplot->objectsLine,contoursplot->nObjectsLine*sizeof(ContoursPlotObjectLine));
2290 	}
2291 
2292 }
2293 /****************************************************************************************/
delete_objects_line(GtkWidget * widget)2294 static void delete_objects_line(GtkWidget *widget)
2295 {
2296 	GabeditContoursPlot *contoursplot = NULL;
2297 	if(!widget) return;
2298 	if(!GTK_IS_WIDGET(widget)) return;
2299 	contoursplot = GABEDIT_ContoursPLOT(widget);
2300 	contoursplot->nObjectsLine = 0;
2301 	if(contoursplot->objectsLine) g_free(contoursplot->objectsLine);
2302 	contoursplot->objectsLine = NULL;
2303 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
2304 }
2305 /****************************************************************************************/
begin_insert_objects_line(GtkWidget * widget)2306 static void begin_insert_objects_line(GtkWidget *widget)
2307 {
2308 	if(!widget) return;
2309 	if(!GTK_IS_WIDGET(widget)) return;
2310 	GABEDIT_ContoursPLOT(widget)->l_key_pressed = TRUE;
2311 }
2312 /****************************************************************************************/
spin_line_width_changed_value_object(GtkSpinButton * spinbutton,gpointer user_data)2313 static void spin_line_width_changed_value_object(GtkSpinButton *spinbutton, gpointer user_data)
2314 {
2315 	if(user_data && G_IS_OBJECT(user_data))
2316 	{
2317 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
2318 		ContoursPlotObjectLine* objectLine = g_object_get_data(G_OBJECT(spinbutton),"ObjectLine");
2319   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
2320 		if(objectLine) objectLine->width = gtk_spin_button_get_value(spinbutton);
2321 		else
2322 		{
2323 			gint i;
2324 			for (i=0; i<GABEDIT_ContoursPLOT (contoursplot)->nObjectsLine;i++)
2325 			{
2326 				GABEDIT_ContoursPLOT (contoursplot)->objectsLine[i].width = gtk_spin_button_get_value(spinbutton);
2327 			}
2328 		}
2329 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
2330 	}
2331 }
2332 /****************************************************************************************/
spin_line_color_changed_value_object(GtkColorButton * colorbutton,gpointer user_data)2333 static void spin_line_color_changed_value_object(GtkColorButton  *colorbutton, gpointer user_data)
2334 {
2335 	if(user_data && G_IS_OBJECT(user_data))
2336 	{
2337 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
2338 		ContoursPlotObjectLine* objectLine = g_object_get_data(G_OBJECT(colorbutton),"ObjectLine");
2339 		GdkColor c;
2340 		gtk_color_button_get_color (colorbutton, &c);
2341 
2342   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
2343 
2344 		if(objectLine) objectLine->color = c;
2345 		else
2346 		{
2347 			gint i;
2348 			for (i=0; i<GABEDIT_ContoursPLOT (contoursplot)->nObjectsLine;i++)
2349 			{
2350 				GABEDIT_ContoursPLOT (contoursplot)->objectsLine[i].color = c;
2351 			}
2352 		}
2353 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
2354 	}
2355 }
2356 /********************************************************************************************************/
combo_line_style_changed_value_object(GtkComboBox * combobox,gpointer user_data)2357 static void combo_line_style_changed_value_object(GtkComboBox *combobox, gpointer user_data)
2358 {
2359 	GtkTreeIter iter;
2360 	gchar* d = NULL;
2361 
2362 	if (gtk_combo_box_get_active_iter (combobox, &iter))
2363 	{
2364 		GtkTreeModel* model = gtk_combo_box_get_model(combobox);
2365 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
2366 		ContoursPlotObjectLine* objectLine = g_object_get_data(G_OBJECT(combobox),"ObjectLine");
2367   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
2368 
2369 		gtk_tree_model_get (model, &iter, 0, &d, -1);
2370 		if(!d) return;
2371 		if(objectLine)
2372 		{
2373 		if (!strcmp(d,"Solid") ) {  objectLine->style = GDK_LINE_SOLID; }
2374 		else if (!strcmp(d,"On-Off dashed") ) {objectLine->style = GDK_LINE_ON_OFF_DASH; }
2375 		else if (!strcmp(d,"Double dashed") ) { objectLine->style = GDK_LINE_DOUBLE_DASH;}
2376 		}
2377 		else
2378 		{
2379 			gint i;
2380 			for (i=0; i<GABEDIT_ContoursPLOT (contoursplot)->nObjectsLine;i++)
2381 			{
2382 				if (!strcmp(d,"Solid") ) {  GABEDIT_ContoursPLOT (contoursplot)->objectsLine[i].style = GDK_LINE_SOLID; }
2383 				else if (!strcmp(d,"On-Off dashed") ) {GABEDIT_ContoursPLOT (contoursplot)->objectsLine[i].style = GDK_LINE_ON_OFF_DASH; }
2384 				else if (!strcmp(d,"Double dashed") ) { GABEDIT_ContoursPLOT (contoursplot)->objectsLine[i].style = GDK_LINE_DOUBLE_DASH;}
2385 			}
2386 		}
2387 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
2388 	}
2389 }
2390 /****************************************************************************************/
spin_arrow_size_changed_value_object(GtkSpinButton * spinbutton,gpointer user_data)2391 static void spin_arrow_size_changed_value_object(GtkSpinButton *spinbutton, gpointer user_data)
2392 {
2393 	if(user_data && G_IS_OBJECT(user_data))
2394 	{
2395 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
2396 		ContoursPlotObjectLine* objectLine = g_object_get_data(G_OBJECT(spinbutton),"ObjectLine");
2397 
2398   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
2399 
2400 		if(objectLine) objectLine->arrow_size = gtk_spin_button_get_value(spinbutton);
2401 		else
2402 		{
2403 			gint i;
2404 			for (i=0; i<GABEDIT_ContoursPLOT (contoursplot)->nObjectsLine;i++)
2405 			{
2406 				GABEDIT_ContoursPLOT (contoursplot)->objectsLine[i].arrow_size = gtk_spin_button_get_value(spinbutton);
2407 			}
2408 		}
2409 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
2410 	}
2411 }
2412 /********************************************************************************************************/
add_line_types_combo_object(GtkWidget * hbox)2413 static GtkWidget *add_line_types_combo_object(GtkWidget *hbox)
2414 {
2415         GtkTreeIter iter;
2416         GtkTreeStore *store;
2417 	GtkTreeModel *model;
2418 	GtkWidget *combobox;
2419 	GtkCellRenderer *renderer;
2420 
2421 	store = gtk_tree_store_new (1,G_TYPE_STRING);
2422 
2423         gtk_tree_store_append (store, &iter, NULL);
2424         gtk_tree_store_set (store, &iter, 0, "Solid", -1);
2425         gtk_tree_store_append (store, &iter, NULL);
2426         gtk_tree_store_set (store, &iter, 0, "On-Off dashed", -1);
2427         gtk_tree_store_append (store, &iter, NULL);
2428         gtk_tree_store_set (store, &iter, 0, "Double dashed", -1);
2429 
2430         model = GTK_TREE_MODEL (store);
2431 	combobox = gtk_combo_box_new_with_model (model);
2432 	g_object_unref (model);
2433 	gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 1);
2434 	renderer = gtk_cell_renderer_text_new ();
2435 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
2436 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL);
2437 
2438 	return combobox;
2439 }
2440 /****************************************************************************************/
set_object_line_dialog(GabeditContoursPlot * contoursplot,gint i)2441 static void set_object_line_dialog(GabeditContoursPlot* contoursplot, gint i)
2442 {
2443 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2444 	GtkWidget* frame = NULL;
2445 	GtkWidget* hbox = NULL;
2446 	GtkWidget* hbox1 = NULL;
2447 	GtkWidget* label = NULL;
2448 	GtkWidget* combo = NULL;
2449 	GtkWidget* spin = NULL;
2450 	GtkWidget* button = NULL;
2451 	GtkWidget* spin_arrow = NULL;
2452 	GtkWidget* parentWindow = NULL;
2453 	GtkWidget* vbox_window = NULL;
2454 	ContoursPlotObjectLine* objectLine = NULL;
2455 	GdkLineStyle line_style =  GDK_LINE_SOLID;
2456 
2457 	if(i>=0 && i<=contoursplot->nObjectsLine-1) objectLine = &contoursplot->objectsLine[i];
2458 	else return;
2459 	line_style =  objectLine->style;
2460 
2461 	gtk_window_set_title (GTK_WINDOW (window), _("Set line options"));
2462 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2463 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
2464 
2465 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
2466 
2467 	vbox_window=gtk_vbox_new(FALSE, 0);
2468 	gtk_container_add(GTK_CONTAINER(window), vbox_window);
2469 	gtk_widget_show(vbox_window);
2470 
2471 	hbox1=gtk_hbox_new(FALSE, 0);
2472 	gtk_box_pack_start(GTK_BOX(vbox_window), hbox1, TRUE, FALSE, 2);
2473 	gtk_widget_show(hbox1);
2474 
2475 	frame = gtk_frame_new(NULL);
2476 	gtk_box_pack_start(GTK_BOX(hbox1), frame, TRUE, FALSE, 2);
2477 	gtk_widget_show(frame);
2478 
2479 	hbox=gtk_hbox_new(FALSE, 0);
2480 	gtk_container_add(GTK_CONTAINER(frame), hbox);
2481 	gtk_widget_show(hbox);
2482 
2483 	label=gtk_label_new(_("Line width :"));
2484 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
2485 	gtk_widget_show(label);
2486 
2487 	spin = gtk_spin_button_new_with_range(0, 10, 1);
2488 	if(objectLine) gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), objectLine->width);
2489 	else gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 1);
2490 
2491 	gtk_box_pack_start(GTK_BOX(hbox), spin, TRUE, FALSE, 2);
2492 	gtk_widget_show(spin);
2493 	g_object_set_data(G_OBJECT (window), "SpinLineWidth", spin);
2494 
2495 	label=gtk_label_new(_("Line type :"));
2496 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
2497 	gtk_widget_show(label);
2498 
2499 	combo = add_line_types_combo_object(hbox);
2500 	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
2501 	if(objectLine)
2502 	{
2503 		GdkLineStyle line_style =  objectLine->style;
2504 		if(line_style == GDK_LINE_SOLID) gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
2505 		else if(line_style == GDK_LINE_ON_OFF_DASH) gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
2506 		else if(line_style == GDK_LINE_DOUBLE_DASH) gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 2);
2507 	}
2508 	gtk_widget_show(combo);
2509 	g_object_set_data(G_OBJECT (window), "ComboLineType", combo);
2510 
2511 	label=gtk_label_new(_("Line color :"));
2512 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
2513 	gtk_widget_show(label);
2514 
2515 	button = gtk_color_button_new_with_color (&objectLine->color);
2516 	gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 2);
2517 	gtk_widget_show(button);
2518 	g_object_set_data(G_OBJECT (window), "ColorButton", button);
2519 
2520 	label=gtk_label_new(_("Arrow size :"));
2521 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
2522 	gtk_widget_show(label);
2523 
2524 	spin_arrow = gtk_spin_button_new_with_range(0, 30, 1);
2525 
2526 	if(objectLine)
2527 		gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_arrow), objectLine->arrow_size);
2528 	gtk_box_pack_start(GTK_BOX(hbox), spin_arrow, TRUE, FALSE, 2);
2529 	gtk_widget_show(spin_arrow);
2530 	g_object_set_data(G_OBJECT (window), "SpinArrowSize", spin_arrow);
2531 
2532 
2533 	g_object_set_data(G_OBJECT (spin), "ObjectLine", objectLine);
2534 	g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(spin_line_width_changed_value_object), contoursplot);
2535 
2536 	g_object_set_data(G_OBJECT (button), "ObjectLine", objectLine);
2537 	g_signal_connect(G_OBJECT(button), "color-set", G_CALLBACK(spin_line_color_changed_value_object), contoursplot);
2538 
2539 	g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(combo_line_style_changed_value_object), contoursplot);
2540 	g_object_set_data(G_OBJECT (combo), "ObjectLine", objectLine);
2541 
2542 	g_object_set_data(G_OBJECT (spin_arrow), "ObjectLine", objectLine);
2543 	g_signal_connect(G_OBJECT(spin_arrow), "value-changed", G_CALLBACK(spin_arrow_size_changed_value_object), contoursplot);
2544 
2545 
2546 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
2547 	if(parentWindow)
2548 	{
2549 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
2550 	}
2551 	gtk_widget_show(window);
2552 	/* list_utf8();*/
2553 
2554 
2555 }
2556 /**************************************************************************************************/
set_object_image_relative(GabeditContoursPlot * contoursplotplot,ContoursPlotObjectImage * objectImage)2557 static void set_object_image_relative(GabeditContoursPlot *contoursplotplot, ContoursPlotObjectImage* objectImage)
2558 {
2559 	gdouble f = (gdouble)GTK_WIDGET(contoursplotplot)->allocation.width;
2560   	gint xi=objectImage->xi-contoursplotplot->plotting_rect.x;
2561   	gint yi=contoursplotplot->plotting_rect.y+contoursplotplot->plotting_rect.height-objectImage->yi;
2562 	if(f>(gdouble)GTK_WIDGET(contoursplotplot)->allocation.height) f = (gdouble)GTK_WIDGET(contoursplotplot)->allocation.height;
2563 	objectImage->width = (gdouble)objectImage->widthi/f;
2564 	objectImage->height = (gdouble)objectImage->heighti/f;
2565 	/*
2566 	objectImage->x = (gdouble)objectImage->xi/f;
2567 	objectImage->y = (gdouble)objectImage->yi/f;
2568 	*/
2569         pixel2value(contoursplotplot, xi, yi, &objectImage->x, &objectImage->y);
2570 	/* printf("contoursplot = %f %f\n",objectImage->x, objectImage->y);*/
2571 }
2572 /**************************************************************************************************/
set_object_image_pixels(GabeditContoursPlot * contoursplotplot,ContoursPlotObjectImage * objectImage)2573 static void set_object_image_pixels(GabeditContoursPlot *contoursplotplot, ContoursPlotObjectImage* objectImage)
2574 {
2575 	gint xi,yi;
2576 	gdouble f = (gdouble)GTK_WIDGET(contoursplotplot)->allocation.width;
2577 	if(f>(gdouble)GTK_WIDGET(contoursplotplot)->allocation.height) f = (gdouble)GTK_WIDGET(contoursplotplot)->allocation.height;
2578 	objectImage->widthi = (gint)(objectImage->width*f);
2579 	objectImage->heighti = (gint)(objectImage->height*f);
2580 	/*
2581 	objectImage->xi = (gint)(objectImage->x*f);
2582 	objectImage->yi = (gint)(objectImage->y*f);
2583 	*/
2584 
2585        	value2pixel(contoursplotplot, objectImage->x, objectImage->y, &xi, &yi);
2586        	objectImage->xi = xi;
2587 	objectImage->yi = yi;
2588 	objectImage->yi=contoursplotplot->plotting_rect.height-objectImage->yi;
2589 	objectImage->xi += contoursplotplot->plotting_rect.x;
2590 	objectImage->yi += contoursplotplot->plotting_rect.y;
2591 }
2592 /****************************************************************************************/
set_object_image(GabeditContoursPlot * contoursplotplot,ContoursPlotObjectImage * objectImage,gint xi,gint yi,gint w,gint h)2593 static void set_object_image(GabeditContoursPlot *contoursplotplot, ContoursPlotObjectImage* objectImage, gint xi, gint yi, gint w, gint h)
2594 {
2595 	objectImage->xi = xi;
2596 	objectImage->yi = yi;
2597 	objectImage->widthi = w;
2598 	objectImage->heighti = h;
2599 	set_object_image_relative(contoursplotplot, objectImage);
2600 }
2601 /**************************************************************************/
get_image_from_clipboard()2602 static cairo_surface_t* get_image_from_clipboard()
2603 {
2604 	cairo_surface_t *surface = NULL;
2605 	GtkClipboard * clipboard = NULL;
2606 	GdkPixbuf * pixbuf = NULL;
2607 
2608 	clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
2609 	if(!clipboard) return NULL;
2610 	pixbuf = gtk_clipboard_wait_for_image(clipboard);
2611 
2612 	if(pixbuf)
2613 	{
2614 		gint width;
2615                 gint height;
2616 		gint stride;
2617 		gint x,y;
2618 		gint nChannels;
2619 		guchar *p, *pixels;
2620       		gint red, green, blue;
2621       		gfloat alpha;
2622 
2623 		if (!gdk_pixbuf_get_has_alpha (pixbuf))
2624       		{
2625             		GdkPixbuf* newPixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 255, 255, 255);
2626 			if (newPixbuf != pixbuf)
2627 			{
2628 				g_object_unref(pixbuf);
2629 				pixbuf = newPixbuf;
2630 			}
2631 		}
2632 		width = gdk_pixbuf_get_width (pixbuf);
2633                 height = gdk_pixbuf_get_height (pixbuf);
2634 		stride = gdk_pixbuf_get_rowstride(pixbuf);
2635 		nChannels = gdk_pixbuf_get_n_channels (pixbuf);
2636 		pixels = gdk_pixbuf_get_pixels (pixbuf);
2637 
2638 		for (y = 0; y < height; y++)
2639       		{
2640             		for (x = 0; x < width; x++)
2641             		{
2642                   		p = pixels + y * stride + x * nChannels;
2643                   		alpha = (gfloat) p[3] / 255;
2644                   		red = p[0] * alpha;
2645                   		green = p[1] * alpha;
2646                   		blue = p[2] * alpha;
2647                   		p[0] = blue;
2648                   		p[1] = green;
2649                   		p[2] = red;
2650             		}
2651       		}
2652 
2653 		surface = cairo_image_surface_create_for_data(
2654 					pixels,
2655 					CAIRO_FORMAT_ARGB32,
2656                                        	width,
2657                                        	height,
2658                                        	stride);
2659 		/*g_object_unref(pixbuf);*/
2660 	}
2661 	return surface;
2662 }
2663 /**************************************************************************************************/
get_object_image(GabeditContoursPlot * contoursplotplot,gint xi,gint yi,G_CONST_RETURN gchar * fileName)2664 static ContoursPlotObjectImage get_object_image(GabeditContoursPlot *contoursplotplot, gint xi, gint yi, G_CONST_RETURN gchar* fileName)
2665 {
2666 	gint w;
2667 	gint h;
2668 	gint nw;
2669 	gint nh;
2670 	gdouble fw = 1;
2671 	gdouble fh = 1;
2672 	gdouble f = 1;
2673 	ContoursPlotObjectImage objectImage;
2674 	objectImage.widthi=0;
2675 	objectImage.heighti=0;
2676 	objectImage.xi=xi;
2677 	objectImage.yi=yi;
2678 	if(fileName) objectImage.fileName = g_strdup(fileName);
2679 	else objectImage.fileName = NULL;
2680 	objectImage.image=NULL;
2681 	if(fileName)
2682 	{
2683 		objectImage.image = cairo_image_surface_create_from_png (objectImage.fileName);
2684 	}
2685 	else
2686 	{
2687 		objectImage.image = get_image_from_clipboard();
2688 	}
2689         if(!objectImage.image) return objectImage;
2690         w = cairo_image_surface_get_width (objectImage.image);
2691 	h = cairo_image_surface_get_height (objectImage.image);
2692 
2693 	nw = contoursplotplot->plotting_rect.width-xi;
2694 	nh = contoursplotplot->plotting_rect.height-yi;
2695 	if(nw<w && nw>0) fw = nw/(gdouble)w;
2696 	if(nh<h&&nh>0) fh = nh/(gdouble)h;
2697 	f = fw;
2698 	if(f>fh) f = fh;
2699 
2700 	objectImage.widthi = (gint)(w*f);
2701 	objectImage.heighti = (gint)(h*f);
2702 	set_object_image_relative(contoursplotplot, &objectImage);
2703 
2704 	/* printf("w = %d h = %d\n",w, h);*/
2705 	return objectImage;
2706 }
2707 /****************************************************************************************/
add_object_image(GabeditContoursPlot * contoursplotplot,gint xi,gint yi,gint width,gint height,G_CONST_RETURN gchar * fileName)2708 static void add_object_image(GabeditContoursPlot *contoursplotplot, gint xi, gint yi, gint width, gint height, G_CONST_RETURN gchar* fileName)
2709 {
2710 	ContoursPlotObjectImage objectImage = get_object_image(contoursplotplot, xi, yi, fileName);
2711 	if(!objectImage.image) return;
2712 	contoursplotplot->nObjectsImage++;
2713 	if(contoursplotplot->nObjectsImage==1) contoursplotplot->objectsImage = g_malloc(sizeof(ContoursPlotObjectImage));
2714 	else contoursplotplot->objectsImage = g_realloc(contoursplotplot->objectsImage,contoursplotplot->nObjectsImage*sizeof(ContoursPlotObjectImage));
2715 	if(width>0 && height>0)
2716 	{
2717 		objectImage.widthi=width;
2718 		objectImage.heighti=height;
2719 	}
2720 	contoursplotplot->objectsImage[contoursplotplot->nObjectsImage-1] = objectImage;
2721 }
2722 /****************************************************************************************/
get_object_image_num(GabeditContoursPlot * contoursplotplot,gint xi,gint yi)2723 static gint get_object_image_num(GabeditContoursPlot *contoursplotplot, gint xi, gint yi)
2724 {
2725 	gint i;
2726 	if(!contoursplotplot) return -1;
2727 	for(i=0;i<contoursplotplot->nObjectsImage;i++)
2728 	{
2729 		if(xi>=(gint)contoursplotplot->objectsImage[i].xi && yi>=contoursplotplot->objectsImage[i].yi
2730 		&& xi<=contoursplotplot->objectsImage[i].xi+contoursplotplot->objectsImage[i].widthi
2731 		&& yi<=contoursplotplot->objectsImage[i].yi+contoursplotplot->objectsImage[i].heighti)
2732 			return i;
2733 	}
2734 	return -1;
2735 }
2736 /****************************************************************************************/
delete_object_image(GtkWidget * widget,gint i)2737 static void delete_object_image(GtkWidget *widget, gint i)
2738 {
2739 	gint j;
2740 	GabeditContoursPlot *contoursplotplot = NULL;
2741 	if(!widget) return;
2742 	if(!GTK_IS_WIDGET(widget)) return;
2743 	contoursplotplot = GABEDIT_ContoursPLOT(widget);
2744 	if(i<0||i>=contoursplotplot->nObjectsImage) return;
2745 	if(contoursplotplot->objectsImage[i].fileName) g_free(contoursplotplot->objectsImage[i].fileName);
2746 	if(contoursplotplot->objectsImage[i].image) cairo_surface_destroy (contoursplotplot->objectsImage[i].image);
2747 	for(j=i;j<contoursplotplot->nObjectsImage-1;j++)
2748 		contoursplotplot->objectsImage[j] = contoursplotplot->objectsImage[j+1];
2749 	contoursplotplot->nObjectsImage--;
2750 	if(contoursplotplot->nObjectsImage<1)
2751 	{
2752 		contoursplotplot->nObjectsImage = 0;
2753 		if(contoursplotplot->objectsImage) g_free(contoursplotplot->objectsImage);
2754 		contoursplotplot->objectsImage = NULL;
2755 	}
2756 	else
2757 	{
2758 		contoursplotplot->objectsImage = g_realloc(contoursplotplot->objectsImage,contoursplotplot->nObjectsImage*sizeof(ContoursPlotObjectImage));
2759 	}
2760 
2761 }
2762 /****************************************************************************************/
delete_objects_image(GtkWidget * widget)2763 static void delete_objects_image(GtkWidget *widget)
2764 {
2765 	GabeditContoursPlot *contoursplotplot = NULL;
2766 	gint i;
2767 	if(!widget) return;
2768 	if(!GTK_IS_WIDGET(widget)) return;
2769 	contoursplotplot = GABEDIT_ContoursPLOT(widget);
2770 	for(i=0;i<contoursplotplot->nObjectsImage;i++)
2771 	{
2772 		if(contoursplotplot->objectsImage[i].fileName) g_free(contoursplotplot->objectsImage[i].fileName);
2773 		if(contoursplotplot->objectsImage[i].image) cairo_surface_destroy (contoursplotplot->objectsImage[i].image);
2774 	}
2775 	contoursplotplot->nObjectsImage = 0;
2776 	if(contoursplotplot->objectsImage) g_free(contoursplotplot->objectsImage);
2777 	contoursplotplot->objectsImage = NULL;
2778 	gtk_widget_queue_draw(GTK_WIDGET(contoursplotplot));
2779 }
2780 /********************************************************************************/
read_image_png(GtkFileChooser * filesel,gint response_id)2781 static gboolean read_image_png(GtkFileChooser *filesel, gint response_id)
2782 {
2783 	gchar *fileName;
2784 	GtkWidget* contoursplotplot = NULL;
2785 	ContoursPlotObjectImage* objectImage = NULL;
2786 
2787 	if(response_id != GTK_RESPONSE_OK) return FALSE;
2788  	fileName = gtk_file_chooser_get_filename(filesel);
2789 	contoursplotplot = g_object_get_data(G_OBJECT (filesel), "ContoursPLOT");
2790 	objectImage = g_object_get_data(G_OBJECT(filesel),"ObjectImage");
2791 	if(objectImage && !objectImage->image)
2792 	{
2793 		add_object_image(GABEDIT_ContoursPLOT(contoursplotplot), objectImage->xi, objectImage->yi, -1, -1, fileName);
2794 		g_free(objectImage);
2795 	}
2796 	gtk_widget_queue_draw(GTK_WIDGET(contoursplotplot));
2797 	return TRUE;
2798 
2799 }
2800 /********************************************************************************/
activate_entry_object_image(GtkWidget * entry,gpointer user_data)2801 static void activate_entry_object_image(GtkWidget *entry, gpointer user_data)
2802 {
2803 	G_CONST_RETURN gchar* t;
2804 	GtkWidget* contoursplotplot = NULL;
2805 	GtkWidget* window = NULL;
2806 	ContoursPlotObjectImage* objectImage = NULL;
2807 
2808 
2809 	if(!GTK_IS_WIDGET(entry)) return;
2810 	if(!user_data || !G_IS_OBJECT(user_data)) return;
2811 
2812 	contoursplotplot = GTK_WIDGET(user_data);
2813 	t= gtk_entry_get_text(GTK_ENTRY(entry));
2814 	if(!entry) return;
2815 	window = g_object_get_data(G_OBJECT(entry),"Window");
2816 	objectImage = g_object_get_data(G_OBJECT(entry),"ObjectImage");
2817 	/* t is destroyed with window */
2818 	if(!objectImage)
2819 	{
2820 		if(window)gtk_widget_destroy(window);
2821 		return;
2822 	}
2823 	else
2824 	{
2825 		objectImage->widthi =(gint)(fabs(atof(t))*cairo_image_surface_get_width (objectImage->image));
2826 		objectImage->heighti =(gint)(fabs(atof(t))*cairo_image_surface_get_height (objectImage->image));
2827 	}
2828 	if(window)gtk_widget_destroy(window);
2829 	gtk_widget_queue_draw(GTK_WIDGET(contoursplotplot));
2830 }
2831 /********************************************************************************/
add_set_object_image_dialog(GtkWidget * contoursplotplot,gint i,gint xi,gint yi)2832 static void add_set_object_image_dialog(GtkWidget* contoursplotplot, gint i, gint xi, gint yi)
2833 {
2834 	GtkWidget* parentWindow = NULL;
2835 	gchar* patternsfiles[] = {"*.png","*",NULL};
2836 	GtkWidget* filesel= NULL;
2837 	ContoursPlotObjectImage* objectImage = NULL;
2838 
2839 	if(i>-1 && i<GABEDIT_ContoursPLOT(contoursplotplot)->nObjectsImage)
2840 	{
2841 		GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2842 		GtkWidget* frame = NULL;
2843 		GtkWidget* hbox = NULL;
2844 		GtkWidget* vbox_frame = NULL;
2845 		GtkWidget* label = NULL;
2846 		GtkWidget* entry_label = NULL;
2847 
2848 		objectImage = &GABEDIT_ContoursPLOT(contoursplotplot)->objectsImage[i];
2849 
2850 		gtk_window_set_title (GTK_WINDOW (window), _("Scale image"));
2851 		gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2852 		gtk_window_set_modal (GTK_WINDOW (window), TRUE);
2853 
2854 		g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplotplot);
2855 
2856 		hbox=gtk_hbox_new(FALSE, 0);
2857 		gtk_container_add(GTK_CONTAINER(window), hbox);
2858 		gtk_widget_show(hbox);
2859 
2860 		frame=gtk_frame_new(NULL);
2861 		gtk_container_add(GTK_CONTAINER(hbox), frame);
2862 		gtk_widget_show(frame);
2863 
2864 		vbox_frame=gtk_vbox_new(FALSE, 0);
2865 		gtk_container_add(GTK_CONTAINER(frame), vbox_frame);
2866 		gtk_widget_show(vbox_frame);
2867 
2868 		hbox=gtk_hbox_new(FALSE, 0);
2869 		gtk_box_pack_start(GTK_BOX(vbox_frame), hbox, FALSE, FALSE, 2);
2870 		gtk_widget_show(hbox);
2871 
2872 		label=gtk_label_new(_("Factor (new size/orginal size) : "));
2873 		gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
2874 		gtk_widget_show(label);
2875 
2876 		entry_label = gtk_entry_new();
2877 		/* gtk_widget_set_size_request(entry_label,100,-1);*/
2878 
2879 		gtk_entry_set_text(GTK_ENTRY(entry_label),"0.5");
2880 
2881 		gtk_box_pack_start(GTK_BOX(hbox), entry_label, TRUE, TRUE, 2);
2882 		gtk_widget_show(entry_label);
2883 
2884 		g_object_set_data(G_OBJECT(entry_label),"ObjectImage", objectImage);
2885 
2886 		g_object_set_data(G_OBJECT(entry_label),"Window", window);
2887 		g_signal_connect (G_OBJECT (entry_label), "activate", (GCallback)activate_entry_object_image, contoursplotplot);
2888 
2889 		parentWindow = get_parent_window(GTK_WIDGET(contoursplotplot));
2890 		if(parentWindow)
2891 		{
2892 			gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
2893 		}
2894 		gtk_widget_show(window);
2895 	}
2896 	else if(i==-1)
2897 	{
2898 		objectImage = g_malloc(sizeof(ContoursPlotObjectImage));
2899 		objectImage->xi = xi;
2900 		objectImage->yi = yi;
2901 		objectImage->fileName = NULL;
2902 		objectImage->image = NULL;
2903 		parentWindow = get_parent_window(GTK_WIDGET(contoursplotplot));
2904 		filesel= new_file_chooser_open(parentWindow,
2905 				(GCallback *)read_image_png,
2906 				_("Read image from a png file"),
2907 				patternsfiles);
2908 		gtk_window_set_modal (GTK_WINDOW (filesel), TRUE);
2909 		g_object_set_data(G_OBJECT (filesel), "ContoursPLOT", contoursplotplot);
2910 		g_object_set_data(G_OBJECT(filesel),"ObjectImage", objectImage);
2911 	}
2912 	else
2913 		add_object_image(GABEDIT_ContoursPLOT(contoursplotplot), xi, yi, -1, -1, NULL);
2914 
2915 }
2916 /****************************************************************************************/
reset_object_image_pixels(GabeditContoursPlot * contoursplotplot)2917 static void reset_object_image_pixels(GabeditContoursPlot *contoursplotplot)
2918 {
2919 	gint i;
2920 	if(!contoursplotplot) return;
2921 	for(i=0;i<contoursplotplot->nObjectsImage;i++)
2922 		set_object_image_pixels(contoursplotplot, &contoursplotplot->objectsImage[i]);
2923 }
2924 /****************************************************************************************/
2925 /*
2926 static void reset_object_image_relative(GabeditContoursPlot *contoursplotplot)
2927 {
2928 	gint i;
2929 	if(!contoursplotplot) return;
2930 	for(i=0;i<contoursplotplot->nObjectsImage;i++)
2931 		set_object_image_relative(contoursplotplot, &contoursplotplot->objectsImage[i]);
2932 }
2933 */
2934 /****************************************************************************************/
insert_objects_image_from_clipboard(GtkWidget * widget)2935 static void insert_objects_image_from_clipboard(GtkWidget *widget)
2936 {
2937 	if(!widget) return;
2938 	if(!GTK_IS_WIDGET(widget)) return;
2939 	add_object_image(GABEDIT_ContoursPLOT(widget), 0, 0, -1, -1, NULL);
2940         gtk_widget_queue_draw(widget);
2941 }
2942 /****************************************************************************************/
begin_insert_objects_image(GtkWidget * widget)2943 static void begin_insert_objects_image(GtkWidget *widget)
2944 {
2945 	if(!widget) return;
2946 	if(!GTK_IS_WIDGET(widget)) return;
2947 	GABEDIT_ContoursPLOT(widget)->i_key_pressed = TRUE;
2948 }
2949 /********************************************************************************/
read_data(GtkFileChooser * filesel,gint response_id)2950 static gboolean read_data(GtkFileChooser *filesel, gint response_id)
2951 {
2952 	gchar *fileName;
2953  	gboolean OK;
2954  	FILE *fd;
2955 	gint xsize = 0;
2956 	gint ysize = 0;
2957 	gdouble xmin = 0;
2958 	gdouble ymin = 0;
2959 	gdouble xmax = 0;
2960 	gdouble ymax = 0;
2961 	gdouble* zValues = NULL;
2962 	GtkWidget* contoursplot = NULL;
2963 	gint size = 0;
2964 	gint i;
2965 
2966 	if(response_id != GTK_RESPONSE_OK) return FALSE;
2967  	fileName = gtk_file_chooser_get_filename(filesel);
2968 	contoursplot = g_object_get_data(G_OBJECT (filesel), "ContoursPLOT");
2969 
2970  	fd = fopen(fileName, "rb");
2971  	OK=FALSE;
2972 	if(!fd)
2973 	{
2974 		GtkWidget* dialog = NULL;
2975 		gchar* tmp = g_strdup_printf(_("Sorry, I cannot open %s file"),fileName);
2976 		dialog = gtk_message_dialog_new_with_markup (NULL,
2977 		           GTK_DIALOG_DESTROY_WITH_PARENT,
2978 		           GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
2979 			   "%s",
2980 			   tmp);
2981        		gtk_dialog_run (GTK_DIALOG (dialog));
2982        		gtk_widget_destroy (dialog);
2983        		g_free(tmp);
2984 		return FALSE;
2985 	}
2986 	if(fd)
2987 	{
2988 		if(3==fscanf(fd,"%d %lf %lf",&xsize,&xmin,&xmax))
2989 		{
2990 			if(3==fscanf(fd,"%d %lf %lf",&ysize,&ymin,&ymax)) OK = TRUE;
2991 		}
2992 	}
2993 	size = xsize*ysize;
2994 	if(size<1)
2995 	{
2996 		GtkWidget* dialog = NULL;
2997 		gchar* tmp = g_strdup_printf(_("Sorry, I cannot read %s file"),fileName);
2998 		dialog = gtk_message_dialog_new_with_markup (NULL,
2999 		           GTK_DIALOG_DESTROY_WITH_PARENT,
3000 		           GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
3001 			   "%s",
3002 			   tmp);
3003        		gtk_dialog_run (GTK_DIALOG (dialog));
3004        		gtk_widget_destroy (dialog);
3005        		g_free(tmp);
3006 		return FALSE;
3007 	}
3008 	if(OK) zValues = g_malloc(size*sizeof(gdouble));
3009 	if(!zValues)
3010 	{
3011 		GtkWidget* dialog = NULL;
3012 		gchar* tmp = g_strdup_printf(_("Sorry, I cannot read %s file"),fileName);
3013 		dialog = gtk_message_dialog_new_with_markup (NULL,
3014 		           GTK_DIALOG_DESTROY_WITH_PARENT,
3015 		           GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
3016 			   "%s",
3017 			   tmp);
3018        		gtk_dialog_run (GTK_DIALOG (dialog));
3019        		gtk_widget_destroy (dialog);
3020        		g_free(tmp);
3021 		return FALSE;
3022 	}
3023 	for(i=0;OK && i<xsize*ysize;i++)
3024 		if(1!=fscanf(fd,"%lf",&zValues[i])) OK = FALSE;
3025 
3026 	if(!OK)
3027 	{
3028 		GtkWidget* parentWidget = get_parent_window(GTK_WIDGET(contoursplot));
3029 		GtkWindow* parentWindow = NULL;
3030 		if(parentWidget) parentWindow = GTK_WINDOW(parentWidget);
3031 		GtkWidget* dialog = gtk_message_dialog_new (GTK_WINDOW(parentWindow),
3032 				GTK_DIALOG_DESTROY_WITH_PARENT,
3033 				GTK_MESSAGE_ERROR,
3034 				GTK_BUTTONS_CLOSE,
3035 			       _("Error reading file '%s'"),
3036 				fileName);
3037 		gtk_dialog_run (GTK_DIALOG (dialog));
3038 		gtk_widget_destroy (dialog);
3039 	}
3040 	else
3041 	{
3042 		add_new_data(contoursplot, xsize, xmin, xmax, ysize, ymin, ymax, zValues);
3043 		if(GABEDIT_ContoursPLOT(contoursplot)->data_list)
3044 		{
3045 			GList *current_node;
3046 			current_node=g_list_last(GABEDIT_ContoursPLOT(contoursplot)->data_list);
3047 			if(current_node)
3048 			{
3049 				ContoursPlotData* data = (ContoursPlotData*)current_node->data;
3050 				create_contours(contoursplot,data);
3051 			}
3052 		}
3053 	}
3054 
3055 	if(zValues) g_free(zValues);
3056 	fclose(fd);
3057 	return TRUE;
3058 
3059 }
3060 /********************************************************************************/
read_data_dlg(GtkWidget * contoursplot)3061 static void read_data_dlg(GtkWidget* contoursplot)
3062 {
3063 	GtkWidget* parentWindow = NULL;
3064 	gchar* patternsfiles[] = {"*.txt","*",NULL};
3065 	GtkWidget* filesel= NULL;
3066 
3067 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3068 	filesel= new_file_chooser_open(parentWindow,
3069 			(GCallback *)read_data,
3070 			_("Read data from an ASCII grid file(xsize, xmin, xmax, ysize, ymin, ymax, Zvalues)"),
3071 			patternsfiles);
3072 	gtk_window_set_modal (GTK_WINDOW (filesel), TRUE);
3073 	g_object_set_data(G_OBJECT (filesel), "ContoursPLOT", contoursplot);
3074 }
3075 /********************************************************************************/
save_data(GtkFileChooser * filesel,gint response_id)3076 static gboolean save_data(GtkFileChooser *filesel, gint response_id)
3077 {
3078 	gchar *fileName;
3079  	FILE *file;
3080 	ContoursPlotData* data = NULL;
3081 	gint loop;
3082 
3083 	if(response_id != GTK_RESPONSE_OK) return FALSE;
3084  	fileName = gtk_file_chooser_get_filename(filesel);
3085 	data = g_object_get_data(G_OBJECT (filesel), "CurentData");
3086 	if(!data) return FALSE;
3087 
3088  	file = fopen(fileName, "w");
3089 
3090 	fprintf(file, "%d %f %f\n",data->xsize, data->xmin, data->xmax);
3091 	fprintf(file, "%d %f %f\n",data->ysize, data->ymin, data->ymax);
3092 	for(loop=0;loop<data->xsize*data->ysize; loop++)
3093 		fprintf(file, "%f\n",data->zValues[loop]);
3094 	fclose(file);
3095 	return TRUE;
3096 
3097 }
3098 /********************************************************************************/
auto_range_activate(GtkWidget * buttonAutoRange,GtkWidget * contoursplot)3099 static void auto_range_activate(GtkWidget* buttonAutoRange, GtkWidget* contoursplot)
3100 {
3101 	ContoursPlotData* data = NULL;
3102 	data = g_object_get_data(G_OBJECT (buttonAutoRange), "CurentData");
3103 	if(contoursplot) gabedit_contoursplot_set_autorange(GABEDIT_ContoursPLOT(contoursplot), data);
3104 }
3105 /********************************************************************************/
save_data_dlg(GtkWidget * buttonSave,GtkWidget * contoursplot)3106 static void save_data_dlg(GtkWidget* buttonSave, GtkWidget* contoursplot)
3107 {
3108 	GtkWidget* parentWindow = NULL;
3109 	gchar* patternsfiles[] = {"*.txt","*",NULL};
3110 	GtkWidget* filesel= NULL;
3111 	gchar* tmp = NULL;
3112 	gpointer* data = NULL;
3113 
3114 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3115 	filesel= new_file_chooser_save(parentWindow,
3116 			(GCallback *)save_data,
3117 			_("Save data in an ASCII grid file(xsize, xmin, xmax, ysize, ymin, ymax, Zvalues)"),
3118 			patternsfiles);
3119 	gtk_window_set_modal (GTK_WINDOW (filesel), TRUE);
3120 	data = g_object_get_data(G_OBJECT (buttonSave), "CurentData");
3121 	g_object_set_data(G_OBJECT (filesel), "CurentData", data);
3122 	tmp = g_strdup_printf("%s%s%s",g_get_current_dir(),G_DIR_SEPARATOR_S,"contoursplotData.txt");
3123 	gtk_file_chooser_set_filename ((GtkFileChooser *)filesel, tmp);
3124 	if(tmp) g_free(tmp);
3125 	gtk_file_chooser_set_current_name ((GtkFileChooser *)filesel, "contoursplotData.txt");
3126 }
3127 /********************************************************************************/
remove_data(GtkWidget * buttonRemove,gint response_id)3128 static gboolean remove_data(GtkWidget* buttonRemove, gint response_id)
3129 {
3130 	ContoursPlotData* data = NULL;
3131 	GtkWidget*window = NULL;
3132 	GtkWidget*contoursplot = NULL;
3133 
3134 	if(response_id != GTK_RESPONSE_YES) return FALSE;
3135 	data = g_object_get_data(G_OBJECT (buttonRemove), "CurentData");
3136 	window = g_object_get_data(G_OBJECT (buttonRemove), "Window");
3137 	contoursplot = g_object_get_data(G_OBJECT (buttonRemove), "ContoursPLOT");
3138 	if(contoursplot && data)
3139 	{
3140 		gabedit_contoursplot_remove_data(GABEDIT_ContoursPLOT(contoursplot), data);
3141 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
3142 	}
3143 	if(window) gtk_widget_destroy(window);
3144 	return TRUE;
3145 }
3146 /********************************************************************************/
remove_data_dlg(GtkWidget * buttonRemove,GtkWidget * contoursplot)3147 static void remove_data_dlg(GtkWidget* buttonRemove, GtkWidget* contoursplot)
3148 {
3149 	GtkWidget* parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3150 	GtkWidget* dialog = gtk_message_dialog_new (GTK_WINDOW(parentWindow),
3151 			GTK_DIALOG_DESTROY_WITH_PARENT,
3152 			GTK_MESSAGE_QUESTION,
3153 			GTK_BUTTONS_YES_NO,
3154 		       _("Are you sure to delete this data ?")
3155 			);
3156 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);
3157 	g_signal_connect_swapped(dialog, "response", G_CALLBACK (remove_data), buttonRemove);
3158 	gtk_dialog_run (GTK_DIALOG (dialog));
3159 	gtk_widget_destroy (dialog);
3160 }
3161 /****************************************************************************************/
spin_font_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3162 static void spin_font_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3163 {
3164 	if(user_data && G_IS_OBJECT(user_data))
3165 	{
3166 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
3167 		gint fontSize = gtk_spin_button_get_value(spinbutton);
3168 		gchar tmp[100];
3169 		sprintf(tmp,"sans %d",fontSize);
3170 		gabedit_contoursplot_set_font (GABEDIT_ContoursPLOT(contoursplot), tmp);
3171 		reset_object_text_pango(GABEDIT_ContoursPLOT(contoursplot));
3172 	}
3173 }
3174 /****************************************************************************************/
add_font_size_frame(GtkWidget * hbox,GtkWidget * contoursplot)3175 static void add_font_size_frame(GtkWidget* hbox, GtkWidget* contoursplot)
3176 {
3177 	GtkWidget* frame = NULL;
3178 	GtkWidget* hbox_frame = NULL;
3179 	GtkWidget* spin_font_size = NULL;
3180 
3181 	frame=gtk_frame_new(_("Font size"));
3182 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
3183 	gtk_widget_show(frame);
3184 
3185 	hbox_frame=gtk_hbox_new(FALSE, 0);
3186 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
3187 	gtk_widget_show(hbox_frame);
3188 
3189 	hbox=gtk_hbox_new(FALSE, 0);
3190 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3191 	gtk_widget_show(hbox);
3192 
3193 	spin_font_size=gtk_spin_button_new_with_range(8, 30, 1);
3194 	gtk_box_pack_start(GTK_BOX(hbox), spin_font_size, TRUE, FALSE, 2);
3195 	gtk_widget_show(spin_font_size);
3196 
3197 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_font_size), GABEDIT_ContoursPLOT(contoursplot)->font_size);
3198 	g_signal_connect(G_OBJECT(spin_font_size), "value-changed", G_CALLBACK(spin_font_changed_value), contoursplot);
3199 }
3200 /****************************************************************************************/
set_font_size_dialog(GtkWidget * contoursplot)3201 static void set_font_size_dialog(GtkWidget* contoursplot)
3202 {
3203 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3204 	GtkWidget* hbox = NULL;
3205 	GtkWidget* parentWindow = NULL;
3206 
3207 	gtk_window_set_title (GTK_WINDOW (window), _("Set font size"));
3208 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
3209 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
3210 
3211 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
3212 
3213 	hbox=gtk_hbox_new(FALSE, 0);
3214 	gtk_container_add(GTK_CONTAINER(window), hbox);
3215 	gtk_widget_show(hbox);
3216 
3217 	add_font_size_frame(hbox, contoursplot);
3218 
3219 
3220 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3221 	if(parentWindow)
3222 	{
3223 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
3224 	}
3225 	gtk_widget_show(window);
3226 }
3227 /****************************************************************************************/
spin_x_digits_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3228 static void spin_x_digits_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3229 {
3230 	if(user_data && G_IS_OBJECT(user_data))
3231 	{
3232 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
3233 		gabedit_contoursplot_set_x_legends_digits(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3234 	}
3235 }
3236 /****************************************************************************************/
spin_y_digits_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3237 static void spin_y_digits_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3238 {
3239 	if(user_data && G_IS_OBJECT(user_data))
3240 	{
3241 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
3242 		gabedit_contoursplot_set_y_legends_digits(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3243 	}
3244 }
3245 /****************************************************************************************/
add_digits_frame(GtkWidget * hbox,GtkWidget * contoursplot)3246 static void add_digits_frame(GtkWidget* hbox, GtkWidget* contoursplot)
3247 {
3248 	GtkWidget* frame = NULL;
3249 	GtkWidget* hbox_frame = NULL;
3250 	GtkWidget* label = NULL;
3251 	GtkWidget* x_spin_digits = NULL;
3252 	GtkWidget* y_spin_digits = NULL;
3253 
3254 	frame=gtk_frame_new(_("Digits"));
3255 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
3256 	gtk_widget_show(frame);
3257 
3258 	hbox_frame=gtk_hbox_new(FALSE, 0);
3259 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
3260 	gtk_widget_show(hbox_frame);
3261 
3262 	hbox=gtk_hbox_new(FALSE, 0);
3263 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3264 	gtk_widget_show(hbox);
3265 
3266 	label=gtk_label_new(" X ");
3267 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3268 	gtk_widget_show(label);
3269 
3270 	x_spin_digits=gtk_spin_button_new_with_range(0, 30, 1);
3271 	gtk_box_pack_start(GTK_BOX(hbox), x_spin_digits, TRUE, FALSE, 2);
3272 	gtk_widget_show(x_spin_digits);
3273 
3274 	label=gtk_label_new(" Y ");
3275 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3276 	gtk_widget_show(label);
3277 
3278 	y_spin_digits=gtk_spin_button_new_with_range(0, 30, 1);
3279 	gtk_box_pack_start(GTK_BOX(hbox), y_spin_digits, TRUE, FALSE, 2);
3280 	gtk_widget_show(y_spin_digits);
3281 
3282 
3283 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(x_spin_digits), GABEDIT_ContoursPLOT(contoursplot)->x_legends_digits);
3284 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(y_spin_digits), GABEDIT_ContoursPLOT(contoursplot)->y_legends_digits);
3285 
3286 	g_signal_connect(G_OBJECT(x_spin_digits), "value-changed", G_CALLBACK(spin_x_digits_changed_value), contoursplot);
3287 	g_signal_connect(G_OBJECT(y_spin_digits), "value-changed", G_CALLBACK(spin_y_digits_changed_value), contoursplot);
3288 }
3289 /****************************************************************************************/
set_digits_dialog(GtkWidget * contoursplot)3290 static void set_digits_dialog(GtkWidget* contoursplot)
3291 {
3292 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3293 	GtkWidget* hbox = NULL;
3294 	GtkWidget* parentWindow = NULL;
3295 
3296 	gtk_window_set_title (GTK_WINDOW (window), _("Set digits"));
3297 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
3298 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
3299 
3300 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
3301 
3302 	hbox=gtk_hbox_new(FALSE, 0);
3303 	gtk_container_add(GTK_CONTAINER(window), hbox);
3304 	gtk_widget_show(hbox);
3305 	add_digits_frame(hbox, contoursplot);
3306 
3307 
3308 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3309 	if(parentWindow)
3310 	{
3311 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
3312 	}
3313 	gtk_widget_show(window);
3314 }
3315 /********************************************************************************/
activate_entry_xlabel(GtkWidget * entry,gpointer user_data)3316 static void activate_entry_xlabel(GtkWidget *entry, gpointer user_data)
3317 {
3318 	G_CONST_RETURN gchar* t;
3319 	GtkWidget* contoursplot = NULL;
3320 
3321 
3322 	if(!user_data || !G_IS_OBJECT(user_data)) return;
3323 
3324 	contoursplot = GTK_WIDGET(user_data);
3325 	t= gtk_entry_get_text(GTK_ENTRY(entry));
3326 	gabedit_contoursplot_set_x_label (GABEDIT_ContoursPLOT(contoursplot), t);
3327 }
3328 /********************************************************************************/
activate_entry_ylabel(GtkWidget * entry,gpointer user_data)3329 static void activate_entry_ylabel(GtkWidget *entry, gpointer user_data)
3330 {
3331 	G_CONST_RETURN gchar* t;
3332 	GtkWidget* contoursplot = NULL;
3333 
3334 
3335 	if(!user_data || !G_IS_OBJECT(user_data)) return;
3336 
3337 	contoursplot = GTK_WIDGET(user_data);
3338 	t= gtk_entry_get_text(GTK_ENTRY(entry));
3339 	gabedit_contoursplot_set_y_label (GABEDIT_ContoursPLOT(contoursplot), t);
3340 }
3341 /****************************************************************************************/
add_labels_frame(GtkWidget * hbox,GtkWidget * contoursplot)3342 static void add_labels_frame(GtkWidget* hbox, GtkWidget* contoursplot)
3343 {
3344 	GtkWidget* frame = NULL;
3345 	GtkWidget* hbox_frame = NULL;
3346 	GtkWidget* label = NULL;
3347 	GtkWidget* entry_x_label = NULL;
3348 	GtkWidget* entry_y_label = NULL;
3349 
3350 	frame=gtk_frame_new(_("Labels"));
3351 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
3352 	gtk_widget_show(frame);
3353 
3354 	hbox_frame=gtk_hbox_new(FALSE, 0);
3355 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
3356 	gtk_widget_show(hbox_frame);
3357 
3358 	label=gtk_label_new("X : ");
3359 	gtk_box_pack_start(GTK_BOX(hbox_frame), label, FALSE, FALSE, 2);
3360 	gtk_widget_show(label);
3361 
3362 	entry_x_label = gtk_entry_new();
3363 	gtk_widget_set_size_request(entry_x_label,100,-1);
3364 	if(GABEDIT_ContoursPLOT(contoursplot)->h_label_str)
3365 		gtk_entry_set_text(GTK_ENTRY(entry_x_label),GABEDIT_ContoursPLOT(contoursplot)->h_label_str);
3366 	else
3367 		gtk_entry_set_text(GTK_ENTRY(entry_x_label),"");
3368 	gtk_box_pack_start(GTK_BOX(hbox_frame), entry_x_label, FALSE, FALSE, 2);
3369 	gtk_widget_show(entry_x_label);
3370 
3371 	label=gtk_label_new("Y : ");
3372 	gtk_box_pack_start(GTK_BOX(hbox_frame), label, FALSE, FALSE, 2);
3373 	gtk_widget_show(label);
3374 
3375 	entry_y_label = gtk_entry_new();
3376 	gtk_widget_set_size_request(entry_y_label,100,-1);
3377 	if(GABEDIT_ContoursPLOT(contoursplot)->v_label_str)
3378 		gtk_entry_set_text(GTK_ENTRY(entry_y_label),GABEDIT_ContoursPLOT(contoursplot)->v_label_str);
3379 	else
3380 		gtk_entry_set_text(GTK_ENTRY(entry_y_label),"");
3381 	gtk_box_pack_start(GTK_BOX(hbox_frame), entry_y_label, FALSE, FALSE, 2);
3382 	gtk_widget_show(entry_y_label);
3383 
3384 	g_signal_connect (G_OBJECT (entry_x_label), "activate", (GCallback)activate_entry_xlabel, contoursplot);
3385 	g_signal_connect (G_OBJECT (entry_y_label), "activate", (GCallback)activate_entry_ylabel, contoursplot);
3386 }
3387 /****************************************************************************************/
set_labels_dialog(GtkWidget * contoursplot)3388 static void set_labels_dialog(GtkWidget* contoursplot)
3389 {
3390 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3391 	GtkWidget* parentWindow = NULL;
3392 	GtkWidget* hbox = NULL;
3393 
3394 	gtk_window_set_title (GTK_WINDOW (window), _("Set labels"));
3395 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
3396 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
3397 
3398 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
3399 
3400 	hbox=gtk_hbox_new(FALSE, 0);
3401 	gtk_container_add(GTK_CONTAINER(window), hbox);
3402 	gtk_widget_show(hbox);
3403 
3404 	add_labels_frame(hbox, contoursplot);
3405 
3406 
3407 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3408 	if(parentWindow)
3409 	{
3410 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
3411 	}
3412 	gtk_widget_show(window);
3413 }
3414 /********************************************************************************/
activate_entry_xmin(GtkWidget * entry,gpointer user_data)3415 static void activate_entry_xmin(GtkWidget *entry, gpointer user_data)
3416 {
3417 	G_CONST_RETURN gchar* t;
3418 	gdouble a;
3419 	GtkWidget* contoursplot = NULL;
3420 	gdouble xmin;
3421 	gdouble ymin;
3422 	gdouble xmax;
3423 	gdouble ymax;
3424 
3425 
3426 	if(!user_data || !G_IS_OBJECT(user_data)) return;
3427 
3428 	contoursplot = GTK_WIDGET(user_data);
3429 	t= gtk_entry_get_text(GTK_ENTRY(entry));
3430 	a = atof(t);
3431 	gabedit_contoursplot_get_range (GABEDIT_ContoursPLOT(contoursplot), &xmin, &xmax, &ymin, &ymax);
3432 
3433 	if(a>= xmax)
3434 	{
3435 		gchar* tmp = g_strdup_printf("%0.3f",xmin);
3436 		gtk_entry_set_text(GTK_ENTRY(entry),tmp);
3437 		g_free(tmp);
3438 		return;
3439 	}
3440 	gabedit_contoursplot_set_range_xmin (GABEDIT_ContoursPLOT(contoursplot), a);
3441 }
3442 /********************************************************************************/
activate_entry_xmax(GtkWidget * entry,gpointer user_data)3443 static void activate_entry_xmax(GtkWidget *entry, gpointer user_data)
3444 {
3445 	G_CONST_RETURN gchar* t;
3446 	gdouble a;
3447 	GtkWidget* contoursplot = NULL;
3448 	gdouble xmin;
3449 	gdouble ymin;
3450 	gdouble xmax;
3451 	gdouble ymax;
3452 
3453 
3454 	if(!user_data || !G_IS_OBJECT(user_data)) return;
3455 
3456 	contoursplot = GTK_WIDGET(user_data);
3457 	t= gtk_entry_get_text(GTK_ENTRY(entry));
3458 	a = atof(t);
3459 	gabedit_contoursplot_get_range (GABEDIT_ContoursPLOT(contoursplot), &xmin, &xmax, &ymin, &ymax);
3460 
3461 	if(a<=xmin)
3462 	{
3463 		gchar* tmp = g_strdup_printf("%0.3f",xmax);
3464 		gtk_entry_set_text(GTK_ENTRY(entry),tmp);
3465 		g_free(tmp);
3466 		return;
3467 	}
3468 	gabedit_contoursplot_set_range_xmax (GABEDIT_ContoursPLOT(contoursplot), a);
3469 }
3470 /********************************************************************************/
activate_entry_ymin(GtkWidget * entry,gpointer user_data)3471 static void activate_entry_ymin(GtkWidget *entry, gpointer user_data)
3472 {
3473 	G_CONST_RETURN gchar* t;
3474 	gdouble a;
3475 	GtkWidget* contoursplot = NULL;
3476 	gdouble xmin;
3477 	gdouble ymin;
3478 	gdouble xmax;
3479 	gdouble ymax;
3480 
3481 
3482 	if(!user_data || !G_IS_OBJECT(user_data)) return;
3483 
3484 	contoursplot = GTK_WIDGET(user_data);
3485 	t= gtk_entry_get_text(GTK_ENTRY(entry));
3486 	a = atof(t);
3487 	gabedit_contoursplot_get_range (GABEDIT_ContoursPLOT(contoursplot), &xmin, &xmax, &ymin, &ymax);
3488 
3489 	if(a>= ymax)
3490 	{
3491 		gchar* tmp = g_strdup_printf("%0.3f",ymin);
3492 		gtk_entry_set_text(GTK_ENTRY(entry),tmp);
3493 		g_free(tmp);
3494 		return;
3495 	}
3496 	gabedit_contoursplot_set_range_ymin (GABEDIT_ContoursPLOT(contoursplot), a);
3497 }
3498 /********************************************************************************/
activate_entry_ymax(GtkWidget * entry,gpointer user_data)3499 static void activate_entry_ymax(GtkWidget *entry, gpointer user_data)
3500 {
3501 	G_CONST_RETURN gchar* t;
3502 	gdouble a;
3503 	GtkWidget* contoursplot = NULL;
3504 	gdouble xmin;
3505 	gdouble ymin;
3506 	gdouble xmax;
3507 	gdouble ymax;
3508 
3509 
3510 	if(!user_data || !G_IS_OBJECT(user_data)) return;
3511 
3512 	contoursplot = GTK_WIDGET(user_data);
3513 	t= gtk_entry_get_text(GTK_ENTRY(entry));
3514 	a = atof(t);
3515 	gabedit_contoursplot_get_range (GABEDIT_ContoursPLOT(contoursplot), &xmin, &xmax, &ymin, &ymax);
3516 
3517 	if(a<= ymin)
3518 	{
3519 		gchar* tmp = g_strdup_printf("%0.3f",ymax);
3520 		gtk_entry_set_text(GTK_ENTRY(entry),tmp);
3521 		g_free(tmp);
3522 		return;
3523 	}
3524 	gabedit_contoursplot_set_range_ymax (GABEDIT_ContoursPLOT(contoursplot), a);
3525 }
3526 /****************************************************************************************/
add_ranges_frame(GtkWidget * hbox,GtkWidget * contoursplot)3527 static void add_ranges_frame(GtkWidget* hbox, GtkWidget* contoursplot)
3528 {
3529 	GtkWidget* frame = NULL;
3530 	GtkWidget* hbox_frame = NULL;
3531 	GtkWidget* label = NULL;
3532 	GtkWidget* entry_x_min = NULL;
3533 	GtkWidget* entry_x_max = NULL;
3534 	GtkWidget* entry_y_min = NULL;
3535 	GtkWidget* entry_y_max = NULL;
3536 	gchar tmp[100];
3537 
3538 	frame=gtk_frame_new(_("Ranges"));
3539 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
3540 	gtk_widget_show(frame);
3541 
3542 	hbox_frame=gtk_hbox_new(FALSE, 0);
3543 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
3544 	gtk_widget_show(hbox_frame);
3545 
3546 	label=gtk_label_new(_("X Min: "));
3547 	gtk_box_pack_start(GTK_BOX(hbox_frame), label, FALSE, FALSE, 2);
3548 	gtk_widget_show(label);
3549 
3550 	entry_x_min = gtk_entry_new();
3551 	gtk_widget_set_size_request(entry_x_min,50,-1);
3552 	sprintf(tmp,"%0.3f",GABEDIT_ContoursPLOT(contoursplot)->xmin);
3553 	gtk_entry_set_text(GTK_ENTRY(entry_x_min),tmp);
3554 	gtk_box_pack_start(GTK_BOX(hbox_frame), entry_x_min, TRUE, FALSE, 2);
3555 	gtk_widget_show(entry_x_min);
3556 
3557 	label=gtk_label_new(_("X Max: "));
3558 	gtk_box_pack_start(GTK_BOX(hbox_frame), label, FALSE, FALSE, 2);
3559 	gtk_widget_show(label);
3560 
3561 	entry_x_max = gtk_entry_new();
3562 	gtk_widget_set_size_request(entry_x_max,50,-1);
3563 	sprintf(tmp,"%0.3f",GABEDIT_ContoursPLOT(contoursplot)->xmax);
3564 	gtk_entry_set_text(GTK_ENTRY(entry_x_max),tmp);
3565 	gtk_box_pack_start(GTK_BOX(hbox_frame), entry_x_max, TRUE, FALSE, 2);
3566 	gtk_widget_show(entry_x_max);
3567 
3568 	label=gtk_label_new(_("Y Min: "));
3569 	gtk_box_pack_start(GTK_BOX(hbox_frame), label, FALSE, FALSE, 2);
3570 	gtk_widget_show(label);
3571 
3572 	entry_y_min = gtk_entry_new();
3573 	gtk_widget_set_size_request(entry_y_min,50,-1);
3574 	sprintf(tmp,"%0.3f",GABEDIT_ContoursPLOT(contoursplot)->ymin);
3575 	gtk_entry_set_text(GTK_ENTRY(entry_y_min),tmp);
3576 	gtk_box_pack_start(GTK_BOX(hbox_frame), entry_y_min, TRUE, FALSE, 2);
3577 	gtk_widget_show(entry_y_min);
3578 
3579 	label=gtk_label_new(_("Y Max: "));
3580 	gtk_box_pack_start(GTK_BOX(hbox_frame), label, FALSE, FALSE, 2);
3581 	gtk_widget_show(label);
3582 
3583 	entry_y_max = gtk_entry_new();
3584 	gtk_widget_set_size_request(entry_y_max,50,-1);
3585 	sprintf(tmp,"%0.3f",GABEDIT_ContoursPLOT(contoursplot)->ymax);
3586 	gtk_entry_set_text(GTK_ENTRY(entry_y_max),tmp);
3587 	gtk_box_pack_start(GTK_BOX(hbox_frame), entry_y_max, TRUE, FALSE, 2);
3588 	gtk_widget_show(entry_y_max);
3589 
3590 	g_signal_connect (G_OBJECT (entry_x_min), "activate", (GCallback)activate_entry_xmin, contoursplot);
3591 	g_signal_connect (G_OBJECT (entry_x_max), "activate", (GCallback)activate_entry_xmax, contoursplot);
3592 	g_signal_connect (G_OBJECT (entry_y_min), "activate", (GCallback)activate_entry_ymin, contoursplot);
3593 	g_signal_connect (G_OBJECT (entry_y_max), "activate", (GCallback)activate_entry_ymax, contoursplot);
3594 }
3595 /****************************************************************************************/
set_ranges_dialog(GtkWidget * contoursplot)3596 static void set_ranges_dialog(GtkWidget* contoursplot)
3597 {
3598 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3599 	GtkWidget* parentWindow = NULL;
3600 	GtkWidget* hbox = NULL;
3601 
3602 	gtk_window_set_title (GTK_WINDOW (window), _("Set ranges"));
3603 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
3604 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
3605 
3606 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
3607 
3608 	hbox=gtk_hbox_new(FALSE, 0);
3609 	gtk_container_add(GTK_CONTAINER(window), hbox);
3610 	gtk_widget_show(hbox);
3611 
3612 	add_ranges_frame(hbox, contoursplot);
3613 
3614 
3615 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3616 	if(parentWindow)
3617 	{
3618 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
3619 	}
3620 	gtk_widget_show(window);
3621 }
3622 /****************************************************************************************/
spin_hminor_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3623 static void spin_hminor_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3624 {
3625 	if(user_data && G_IS_OBJECT(user_data))
3626 	{
3627 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3628 	gabedit_contoursplot_set_ticks_hminor(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3629 	}
3630 }
3631 /****************************************************************************************/
spin_hmajor_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3632 static void spin_hmajor_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3633 {
3634 	if(user_data && G_IS_OBJECT(user_data))
3635 	{
3636 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3637 	gabedit_contoursplot_set_ticks_hmajor(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3638 	}
3639 }
3640 /****************************************************************************************/
spin_vminor_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3641 static void spin_vminor_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3642 {
3643 	if(user_data && G_IS_OBJECT(user_data))
3644 	{
3645 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3646 	gabedit_contoursplot_set_ticks_vminor(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3647 	}
3648 }
3649 /****************************************************************************************/
spin_vmajor_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3650 static void spin_vmajor_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3651 {
3652 	if(user_data && G_IS_OBJECT(user_data))
3653 	{
3654 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3655 	gabedit_contoursplot_set_ticks_vmajor(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3656 	}
3657 }
3658 /****************************************************************************************/
spin_length_ticks_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3659 static void spin_length_ticks_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3660 {
3661 	if(user_data && G_IS_OBJECT(user_data))
3662 	{
3663 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3664 	gabedit_contoursplot_set_ticks_length(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3665 	}
3666 }
3667 /****************************************************************************************/
add_ticks_frame(GtkWidget * hbox,GtkWidget * contoursplot)3668 static void add_ticks_frame(GtkWidget* hbox, GtkWidget* contoursplot)
3669 {
3670 	GtkWidget* frame = NULL;
3671 	GtkWidget* hbox_frame = NULL;
3672 	GtkWidget* label = NULL;
3673 	GtkWidget* spin_hmajor = NULL;
3674 	GtkWidget* spin_hminor = NULL;
3675 	GtkWidget* spin_vmajor = NULL;
3676 	GtkWidget* spin_vminor = NULL;
3677 	GtkWidget* spin_length = NULL;
3678 
3679 	frame=gtk_frame_new(_("Ticks"));
3680 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
3681 	gtk_widget_show(frame);
3682 
3683 	hbox_frame=gtk_hbox_new(FALSE, 0);
3684 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
3685 	gtk_widget_show(hbox_frame);
3686 
3687 	hbox=gtk_hbox_new(FALSE, 0);
3688 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3689 	gtk_widget_show(hbox);
3690 
3691 	label=gtk_label_new(_("X Major: "));
3692 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3693 	gtk_widget_show(label);
3694 
3695 	spin_hmajor=gtk_spin_button_new_with_range(0, 30, 1);
3696 	gtk_box_pack_start(GTK_BOX(hbox), spin_hmajor, TRUE, FALSE, 2);
3697 	gtk_widget_show(spin_hmajor);
3698 
3699 	hbox=gtk_hbox_new(FALSE, 0);
3700 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3701 	gtk_widget_show(hbox);
3702 
3703 	label=gtk_label_new(_("Y Major: "));
3704 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3705 	gtk_widget_show(label);
3706 
3707 	spin_vmajor=gtk_spin_button_new_with_range(0, 30, 1);
3708 	gtk_box_pack_start(GTK_BOX(hbox), spin_vmajor, TRUE, FALSE, 2);
3709 	gtk_widget_show(spin_vmajor);
3710 
3711 	hbox=gtk_hbox_new(FALSE, 0);
3712 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3713 	gtk_widget_show(hbox);
3714 
3715 	label=gtk_label_new(_("X Minor: "));
3716 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3717 	gtk_widget_show(label);
3718 
3719 	spin_hminor=gtk_spin_button_new_with_range(0, 30, 1);
3720 	gtk_box_pack_start(GTK_BOX(hbox), spin_hminor, TRUE, FALSE, 2);
3721 	gtk_widget_show(spin_hminor);
3722 
3723 	hbox=gtk_hbox_new(FALSE, 0);
3724 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3725 	gtk_widget_show(hbox);
3726 
3727 	label=gtk_label_new(_("Y Minor: "));
3728 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3729 	gtk_widget_show(label);
3730 
3731 	spin_vminor=gtk_spin_button_new_with_range(0, 30, 1);
3732 	gtk_box_pack_start(GTK_BOX(hbox), spin_vminor, TRUE, FALSE, 2);
3733 	gtk_widget_show(spin_vminor);
3734 
3735 	hbox=gtk_hbox_new(FALSE, 0);
3736 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3737 	gtk_widget_show(hbox);
3738 
3739 	label=gtk_label_new(_("Length: "));
3740 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3741 	gtk_widget_show(label);
3742 
3743 	spin_length=gtk_spin_button_new_with_range(3, 30, 1);
3744 	gtk_box_pack_start(GTK_BOX(hbox), spin_length, TRUE, FALSE, 2);
3745 	gtk_widget_show(spin_length);
3746 
3747 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_hmajor), GABEDIT_ContoursPLOT(contoursplot)->hmajor_ticks);
3748 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_hminor), GABEDIT_ContoursPLOT(contoursplot)->hminor_ticks);
3749 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_vmajor), GABEDIT_ContoursPLOT(contoursplot)->vmajor_ticks);
3750 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_vminor), GABEDIT_ContoursPLOT(contoursplot)->vminor_ticks);
3751 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_length), GABEDIT_ContoursPLOT(contoursplot)->length_ticks);
3752 
3753 	g_signal_connect(G_OBJECT(spin_hmajor), "value-changed", G_CALLBACK(spin_hmajor_changed_value), contoursplot);
3754 	g_signal_connect(G_OBJECT(spin_hminor), "value-changed", G_CALLBACK(spin_hminor_changed_value), contoursplot);
3755 	g_signal_connect(G_OBJECT(spin_vmajor), "value-changed", G_CALLBACK(spin_vmajor_changed_value), contoursplot);
3756 	g_signal_connect(G_OBJECT(spin_vminor), "value-changed", G_CALLBACK(spin_vminor_changed_value), contoursplot);
3757 	g_signal_connect(G_OBJECT(spin_length), "value-changed", G_CALLBACK(spin_length_ticks_changed_value), contoursplot);
3758 }
3759 /****************************************************************************************/
set_ticks_dialog(GtkWidget * contoursplot)3760 static void set_ticks_dialog(GtkWidget* contoursplot)
3761 {
3762 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3763 	GtkWidget* hbox = NULL;
3764 	GtkWidget* parentWindow = NULL;
3765 
3766 	gtk_window_set_title (GTK_WINDOW (window), _("Set ticks"));
3767 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
3768 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
3769 
3770 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
3771 
3772 	hbox=gtk_hbox_new(FALSE, 0);
3773 	gtk_container_add(GTK_CONTAINER(window), hbox);
3774 	gtk_widget_show(hbox);
3775 
3776 	add_ticks_frame(hbox, contoursplot);
3777 
3778 
3779 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3780 	if(parentWindow)
3781 	{
3782 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
3783 	}
3784 	gtk_widget_show(window);
3785 }
3786 /****************************************************************************************/
spin_right_margins_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3787 static void spin_right_margins_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3788 {
3789 	if(user_data && G_IS_OBJECT(user_data))
3790 	{
3791 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3792 	gabedit_contoursplot_set_margins_right(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3793 	}
3794 }
3795 /****************************************************************************************/
spin_left_margins_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3796 static void spin_left_margins_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3797 {
3798 	if(user_data && G_IS_OBJECT(user_data))
3799 	{
3800 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3801 	gabedit_contoursplot_set_margins_left(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3802 	}
3803 }
3804 /****************************************************************************************/
spin_bottom_margins_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3805 static void spin_bottom_margins_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3806 {
3807 	if(user_data && G_IS_OBJECT(user_data))
3808 	{
3809 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3810 	gabedit_contoursplot_set_margins_bottom(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3811 	}
3812 }
3813 /****************************************************************************************/
spin_top_margins_changed_value(GtkSpinButton * spinbutton,gpointer user_data)3814 static void spin_top_margins_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
3815 {
3816 	if(user_data && G_IS_OBJECT(user_data))
3817 	{
3818 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3819 	gabedit_contoursplot_set_margins_top(GABEDIT_ContoursPLOT(contoursplot), gtk_spin_button_get_value(spinbutton));
3820 	}
3821 }
3822 /****************************************************************************************/
add_margins_frame(GtkWidget * hbox,GtkWidget * contoursplot)3823 static void add_margins_frame(GtkWidget* hbox, GtkWidget* contoursplot)
3824 {
3825 	GtkWidget* frame = NULL;
3826 	GtkWidget* hbox_frame = NULL;
3827 	GtkWidget* label = NULL;
3828 	GtkWidget* spin_left_margins = NULL;
3829 	GtkWidget* spin_right_margins = NULL;
3830 	GtkWidget* spin_top_margins = NULL;
3831 	GtkWidget* spin_bottom_margins = NULL;
3832 
3833 	frame=gtk_frame_new(_("Margins"));
3834 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
3835 	gtk_widget_show(frame);
3836 
3837 	hbox_frame=gtk_hbox_new(FALSE, 0);
3838 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
3839 	gtk_widget_show(hbox_frame);
3840 
3841 	hbox=gtk_hbox_new(FALSE, 0);
3842 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3843 	gtk_widget_show(hbox);
3844 
3845 	label=gtk_label_new(_("Left: "));
3846 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3847 	gtk_widget_show(label);
3848 
3849 	spin_left_margins=gtk_spin_button_new_with_range(0, 30, 1);
3850 	gtk_box_pack_start(GTK_BOX(hbox), spin_left_margins, TRUE, FALSE, 2);
3851 	gtk_widget_show(spin_left_margins);
3852 
3853 	hbox=gtk_hbox_new(FALSE, 0);
3854 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3855 	gtk_widget_show(hbox);
3856 
3857 	label=gtk_label_new(_("Top: "));
3858 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3859 	gtk_widget_show(label);
3860 
3861 	spin_top_margins=gtk_spin_button_new_with_range(0, 30, 1);
3862 	gtk_box_pack_start(GTK_BOX(hbox), spin_top_margins, TRUE, FALSE, 2);
3863 	gtk_widget_show(spin_top_margins);
3864 
3865 	hbox=gtk_hbox_new(FALSE, 0);
3866 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3867 	gtk_widget_show(hbox);
3868 
3869 	label=gtk_label_new(_("Right: "));
3870 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3871 	gtk_widget_show(label);
3872 
3873 	spin_right_margins=gtk_spin_button_new_with_range(0, 30, 1);
3874 	gtk_box_pack_start(GTK_BOX(hbox), spin_right_margins, TRUE, FALSE, 2);
3875 	gtk_widget_show(spin_right_margins);
3876 
3877 	hbox=gtk_hbox_new(FALSE, 0);
3878 	gtk_container_add(GTK_CONTAINER(hbox_frame), hbox);
3879 	gtk_widget_show(hbox);
3880 
3881 	label=gtk_label_new(_("Bottom: "));
3882 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
3883 	gtk_widget_show(label);
3884 
3885 	spin_bottom_margins=gtk_spin_button_new_with_range(0, 30, 1);
3886 	gtk_box_pack_start(GTK_BOX(hbox), spin_bottom_margins, TRUE, FALSE, 2);
3887 	gtk_widget_show(spin_bottom_margins);
3888 
3889 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_left_margins), GABEDIT_ContoursPLOT(contoursplot)->left_margins);
3890 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_right_margins), GABEDIT_ContoursPLOT(contoursplot)->right_margins);
3891 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_top_margins), GABEDIT_ContoursPLOT(contoursplot)->top_margins);
3892 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_bottom_margins), GABEDIT_ContoursPLOT(contoursplot)->bottom_margins);
3893 
3894 	g_signal_connect(G_OBJECT(spin_left_margins), "value-changed", G_CALLBACK(spin_left_margins_changed_value), contoursplot);
3895 	g_signal_connect(G_OBJECT(spin_right_margins), "value-changed", G_CALLBACK(spin_right_margins_changed_value), contoursplot);
3896 	g_signal_connect(G_OBJECT(spin_top_margins), "value-changed", G_CALLBACK(spin_top_margins_changed_value), contoursplot);
3897 	g_signal_connect(G_OBJECT(spin_bottom_margins), "value-changed", G_CALLBACK(spin_bottom_margins_changed_value), contoursplot);
3898 }
3899 /****************************************************************************************/
set_margins_dialog(GtkWidget * contoursplot)3900 static void set_margins_dialog(GtkWidget* contoursplot)
3901 {
3902 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3903 	GtkWidget* hbox = NULL;
3904 	GtkWidget* parentWindow = NULL;
3905 
3906 	gtk_window_set_title (GTK_WINDOW (window), _("Set margins"));
3907 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
3908 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
3909 
3910 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
3911 
3912 	hbox=gtk_hbox_new(FALSE, 0);
3913 	gtk_container_add(GTK_CONTAINER(window), hbox);
3914 	gtk_widget_show(hbox);
3915 
3916 	add_margins_frame(hbox, contoursplot);
3917 
3918 
3919 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
3920 	if(parentWindow)
3921 	{
3922 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
3923 	}
3924 	gtk_widget_show(window);
3925 }
3926 /****************************************************************************************/
reflect_x_toggled(GtkToggleButton * togglebutton,gpointer user_data)3927 static void reflect_x_toggled(GtkToggleButton *togglebutton, gpointer user_data)
3928 {
3929 	if(user_data && G_IS_OBJECT(user_data))
3930 	{
3931 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3932 	gabedit_contoursplot_reflect_x (GABEDIT_ContoursPLOT(contoursplot), gtk_toggle_button_get_active(togglebutton));
3933 	}
3934 }
3935 /****************************************************************************************/
reflect_y_toggled(GtkToggleButton * togglebutton,gpointer user_data)3936 static void reflect_y_toggled(GtkToggleButton *togglebutton, gpointer user_data)
3937 {
3938 	if(user_data && G_IS_OBJECT(user_data))
3939 	{
3940 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3941 	gabedit_contoursplot_reflect_y (GABEDIT_ContoursPLOT(contoursplot), gtk_toggle_button_get_active(togglebutton));
3942 	}
3943 }
3944 /****************************************************************************************/
add_reflexion_frame(GtkWidget * hbox,GtkWidget * contoursplot)3945 static void add_reflexion_frame(GtkWidget* hbox, GtkWidget* contoursplot)
3946 {
3947 	GtkWidget* frame = NULL;
3948 	GtkWidget* hbox_frame = NULL;
3949 	GtkWidget* reflect_x_button;
3950 	GtkWidget* reflect_y_button;
3951 
3952 	frame=gtk_frame_new(_("Axes"));
3953 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
3954 	gtk_widget_show(frame);
3955 
3956 	hbox_frame=gtk_hbox_new(FALSE, 0);
3957 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
3958 	gtk_widget_show(hbox_frame);
3959 
3960 	reflect_x_button = gtk_check_button_new_with_label (_("Reflect X"));
3961 	gtk_box_pack_start(GTK_BOX(hbox_frame), reflect_x_button, FALSE, FALSE, 2);
3962 	gtk_widget_show(reflect_x_button);
3963 
3964 	reflect_y_button = gtk_check_button_new_with_label (_("Reflect Y"));
3965 	gtk_box_pack_start(GTK_BOX(hbox_frame), reflect_y_button, FALSE, FALSE, 2);
3966 	gtk_widget_show(reflect_y_button);
3967 
3968 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reflect_x_button), GABEDIT_ContoursPLOT(contoursplot)->reflect_x);
3969 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reflect_y_button), GABEDIT_ContoursPLOT(contoursplot)->reflect_y);
3970 
3971 	g_signal_connect (G_OBJECT (reflect_x_button), "toggled", (GCallback)reflect_x_toggled, contoursplot);
3972 	g_signal_connect (G_OBJECT (reflect_y_button), "toggled", (GCallback)reflect_y_toggled, contoursplot);
3973 }
3974 /****************************************************************************************/
show_left_toggled(GtkToggleButton * togglebutton,gpointer user_data)3975 static void show_left_toggled(GtkToggleButton *togglebutton, gpointer user_data)
3976 {
3977 	if(user_data && G_IS_OBJECT(user_data))
3978 	{
3979 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3980 	gabedit_contoursplot_show_left_legends (GABEDIT_ContoursPLOT(contoursplot), gtk_toggle_button_get_active(togglebutton));
3981 	}
3982 }
3983 /****************************************************************************************/
show_right_toggled(GtkToggleButton * togglebutton,gpointer user_data)3984 static void show_right_toggled(GtkToggleButton *togglebutton, gpointer user_data)
3985 {
3986 	if(user_data && G_IS_OBJECT(user_data))
3987 	{
3988 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3989 	gabedit_contoursplot_show_right_legends (GABEDIT_ContoursPLOT(contoursplot), gtk_toggle_button_get_active(togglebutton));
3990 	}
3991 }
3992 /****************************************************************************************/
show_top_toggled(GtkToggleButton * togglebutton,gpointer user_data)3993 static void show_top_toggled(GtkToggleButton *togglebutton, gpointer user_data)
3994 {
3995 	if(user_data && G_IS_OBJECT(user_data))
3996 	{
3997 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
3998 	gabedit_contoursplot_show_top_legends (GABEDIT_ContoursPLOT(contoursplot), gtk_toggle_button_get_active(togglebutton));
3999 	}
4000 }
4001 /****************************************************************************************/
show_bottom_toggled(GtkToggleButton * togglebutton,gpointer user_data)4002 static void show_bottom_toggled(GtkToggleButton *togglebutton, gpointer user_data)
4003 {
4004 	if(user_data && G_IS_OBJECT(user_data))
4005 	{
4006 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
4007 	gabedit_contoursplot_show_bottom_legends (GABEDIT_ContoursPLOT(contoursplot), gtk_toggle_button_get_active(togglebutton));
4008 	}
4009 }
4010 /****************************************************************************************/
add_legends_frame(GtkWidget * hbox,GtkWidget * contoursplot)4011 static void add_legends_frame(GtkWidget* hbox, GtkWidget* contoursplot)
4012 {
4013 	GtkWidget* frame = NULL;
4014 	GtkWidget* hbox_frame = NULL;
4015 	GtkWidget* show_left;
4016 	GtkWidget* show_right;
4017 	GtkWidget* show_top;
4018 	GtkWidget* show_bottom;
4019 
4020 	frame=gtk_frame_new("Legends");
4021 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
4022 	gtk_widget_show(frame);
4023 
4024 	hbox_frame=gtk_hbox_new(FALSE, 0);
4025 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
4026 	gtk_widget_show(hbox_frame);
4027 
4028 	show_left = gtk_check_button_new_with_label (_("Left"));
4029 	gtk_box_pack_start(GTK_BOX(hbox_frame), show_left, FALSE, FALSE, 2);
4030 	gtk_widget_show(show_left);
4031 
4032 	show_right = gtk_check_button_new_with_label (_("Right"));
4033 	gtk_box_pack_start(GTK_BOX(hbox_frame), show_right, FALSE, FALSE, 2);
4034 	gtk_widget_show(show_right);
4035 
4036 	show_top = gtk_check_button_new_with_label (_("Top"));
4037 	gtk_box_pack_start(GTK_BOX(hbox_frame), show_top, FALSE, FALSE, 2);
4038 	gtk_widget_show(show_top);
4039 
4040 	show_bottom = gtk_check_button_new_with_label (_("Bottom"));
4041 	gtk_box_pack_start(GTK_BOX(hbox_frame), show_bottom, FALSE, FALSE, 2);
4042 	gtk_widget_show(show_bottom);
4043 
4044 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_left), GABEDIT_ContoursPLOT(contoursplot)->show_left_legends);
4045 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_right), GABEDIT_ContoursPLOT(contoursplot)->show_right_legends);
4046 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_top), GABEDIT_ContoursPLOT(contoursplot)->show_top_legends);
4047 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_bottom), GABEDIT_ContoursPLOT(contoursplot)->show_bottom_legends);
4048 
4049 	g_signal_connect (G_OBJECT (show_left), "toggled", (GCallback)show_left_toggled, contoursplot);
4050 	g_signal_connect (G_OBJECT (show_right), "toggled", (GCallback)show_right_toggled, contoursplot);
4051 	g_signal_connect (G_OBJECT (show_top), "toggled", (GCallback)show_top_toggled, contoursplot);
4052 	g_signal_connect (G_OBJECT (show_bottom), "toggled", (GCallback)show_bottom_toggled, contoursplot);
4053 }
4054 /****************************************************************************************/
h_major_grids_toggled(GtkToggleButton * togglebutton,gpointer user_data)4055 static void h_major_grids_toggled(GtkToggleButton *togglebutton, gpointer user_data)
4056 {
4057 	if(user_data && G_IS_OBJECT(user_data))
4058 	{
4059 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
4060 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMAJOR_GRID, gtk_toggle_button_get_active(togglebutton));
4061 	}
4062 }
4063 /****************************************************************************************/
h_minor_grids_toggled(GtkToggleButton * togglebutton,gpointer user_data)4064 static void h_minor_grids_toggled(GtkToggleButton *togglebutton, gpointer user_data)
4065 {
4066 	if(user_data && G_IS_OBJECT(user_data))
4067 	{
4068 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
4069 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMINOR_GRID, gtk_toggle_button_get_active(togglebutton));
4070 	}
4071 }
4072 /****************************************************************************************/
v_major_grids_toggled(GtkToggleButton * togglebutton,gpointer user_data)4073 static void v_major_grids_toggled(GtkToggleButton *togglebutton, gpointer user_data)
4074 {
4075 	if(user_data && G_IS_OBJECT(user_data))
4076 	{
4077 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
4078 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMAJOR_GRID, gtk_toggle_button_get_active(togglebutton));
4079 	}
4080 }
4081 /****************************************************************************************/
v_minor_grids_toggled(GtkToggleButton * togglebutton,gpointer user_data)4082 static void v_minor_grids_toggled(GtkToggleButton *togglebutton, gpointer user_data)
4083 {
4084 	if(user_data && G_IS_OBJECT(user_data))
4085 	{
4086 	GtkWidget* contoursplot = GTK_WIDGET(user_data);
4087 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMINOR_GRID, gtk_toggle_button_get_active(togglebutton));
4088 	}
4089 }
4090 /****************************************************************************************/
add_grid_frame(GtkWidget * hbox,GtkWidget * contoursplot)4091 static void add_grid_frame(GtkWidget* hbox, GtkWidget* contoursplot)
4092 {
4093 	GtkWidget* frame = NULL;
4094 	GtkWidget* hbox_frame = NULL;
4095 	GtkWidget* h_major;
4096 	GtkWidget* h_minor;
4097 	GtkWidget* v_major;
4098 	GtkWidget* v_minor;
4099 
4100 	frame=gtk_frame_new(_("Grid"));
4101 	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 2);
4102 	gtk_widget_show(frame);
4103 
4104 	hbox_frame=gtk_hbox_new(FALSE, 0);
4105 	gtk_container_add(GTK_CONTAINER(frame), hbox_frame);
4106 	gtk_widget_show(hbox_frame);
4107 
4108 	h_major = gtk_check_button_new_with_label (_("H major"));
4109 	gtk_box_pack_start(GTK_BOX(hbox_frame), h_major, FALSE, FALSE, 2);
4110 	gtk_widget_show(h_major);
4111 
4112 	v_major = gtk_check_button_new_with_label (_("V major"));
4113 	gtk_box_pack_start(GTK_BOX(hbox_frame), v_major, FALSE, FALSE, 2);
4114 	gtk_widget_show(v_major);
4115 
4116 	h_minor = gtk_check_button_new_with_label (_("H minor"));
4117 	gtk_box_pack_start(GTK_BOX(hbox_frame), h_minor, FALSE, FALSE, 2);
4118 	gtk_widget_show(h_minor);
4119 
4120 	v_minor = gtk_check_button_new_with_label (_("V minor"));
4121 	gtk_box_pack_start(GTK_BOX(hbox_frame), v_minor, FALSE, FALSE, 2);
4122 	gtk_widget_show(v_minor);
4123 
4124 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(h_major), GABEDIT_ContoursPLOT(contoursplot)->hmajor_grid);
4125 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(h_minor), GABEDIT_ContoursPLOT(contoursplot)->hminor_grid);
4126 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v_major), GABEDIT_ContoursPLOT(contoursplot)->vmajor_grid);
4127 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v_minor), GABEDIT_ContoursPLOT(contoursplot)->vminor_grid);
4128 
4129 	g_signal_connect (G_OBJECT (h_major), "toggled", (GCallback)h_major_grids_toggled, contoursplot);
4130 	g_signal_connect (G_OBJECT (h_minor), "toggled", (GCallback)h_minor_grids_toggled, contoursplot);
4131 	g_signal_connect (G_OBJECT (v_major), "toggled", (GCallback)v_major_grids_toggled, contoursplot);
4132 	g_signal_connect (G_OBJECT (v_minor), "toggled", (GCallback)v_minor_grids_toggled, contoursplot);
4133 }
4134 /****************************************************************************************/
set_all_dialog(GtkWidget * contoursplot)4135 static void set_all_dialog(GtkWidget* contoursplot)
4136 {
4137 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4138 	GtkWidget* parentWindow = NULL;
4139 	GtkWidget* hbox = NULL;
4140 	GtkWidget* vbox = NULL;
4141 
4142 	gtk_window_set_title (GTK_WINDOW (window), _("Set"));
4143 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
4144 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
4145 
4146 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
4147 
4148 	vbox=gtk_vbox_new(FALSE, 0);
4149 	gtk_container_add(GTK_CONTAINER(window), vbox);
4150 	gtk_widget_show(vbox);
4151 
4152 	hbox=gtk_hbox_new(FALSE, 0);
4153 	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 1);
4154 	add_ranges_frame(hbox, contoursplot);
4155 	gtk_widget_show(hbox);
4156 
4157 	hbox=gtk_hbox_new(FALSE, 0);
4158 	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 1);
4159 	add_margins_frame(hbox, contoursplot);
4160 	gtk_widget_show(hbox);
4161 
4162 	hbox=gtk_hbox_new(FALSE, 0);
4163 	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 1);
4164 	add_labels_frame(hbox, contoursplot);
4165 	add_font_size_frame(hbox, contoursplot);
4166 	add_digits_frame(hbox, contoursplot);
4167 	gtk_widget_show(hbox);
4168 
4169 	hbox=gtk_hbox_new(FALSE, 0);
4170 	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 1);
4171 	add_ticks_frame(hbox, contoursplot);
4172 	gtk_widget_show(hbox);
4173 
4174 	hbox=gtk_hbox_new(FALSE, 0);
4175 	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 1);
4176 	add_reflexion_frame(hbox, contoursplot);
4177 	add_legends_frame(hbox, contoursplot);
4178 	add_grid_frame(hbox, contoursplot);
4179 	gtk_widget_show(hbox);
4180 
4181 
4182 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
4183 	if(parentWindow)
4184 	{
4185 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
4186 	}
4187 	gtk_widget_show(window);
4188 }
4189 /****************************************************************************************/
gabedit_contoursplot_save_gabedit_lines(GabeditContoursPlot * contoursplot,FILE * file)4190 static void gabedit_contoursplot_save_gabedit_lines(GabeditContoursPlot *contoursplot, FILE* file)
4191 {
4192 	gint i;
4193 	fprintf(file,"lines %d\n", contoursplot->nObjectsLine);
4194 	for(i=0;i<contoursplot->nObjectsLine;i++)
4195 	{
4196 		fprintf(file,"%lf %lf %lf %lf %d %d %lf %lf %lf %d\n",
4197 				contoursplot->objectsLine[i].x1,
4198 				contoursplot->objectsLine[i].y1,
4199 				contoursplot->objectsLine[i].x2,
4200 				contoursplot->objectsLine[i].y2,
4201 				contoursplot->objectsLine[i].width,
4202 				contoursplot->objectsLine[i].arrow_size,
4203 				SCALE(contoursplot->objectsLine[i].color.red),
4204 				SCALE(contoursplot->objectsLine[i].color.green),
4205 				SCALE(contoursplot->objectsLine[i].color.blue),
4206 				contoursplot->objectsLine[i].style
4207 		       );
4208 	}
4209 }
4210 /****************************************************************************************/
gabedit_contoursplot_save_gabedit_texts(GabeditContoursPlot * contoursplot,FILE * file)4211 static void gabedit_contoursplot_save_gabedit_texts(GabeditContoursPlot *contoursplot, FILE* file)
4212 {
4213 	gint i;
4214 	fprintf(file,"texts %d\n", contoursplot->nObjectsText);
4215 	for(i=0;i<contoursplot->nObjectsText;i++)
4216 	{
4217 		fprintf(file,"%lf %lf %lf\n",
4218 				contoursplot->objectsText[i].x,
4219 				contoursplot->objectsText[i].y,
4220 				contoursplot->objectsText[i].angle
4221 		       );
4222 		fprintf(file,"%s\n", contoursplot->objectsText[i].str);
4223 	}
4224 }
4225 /*************************************************************************************/
get_suffix_name_file(const gchar * allname)4226 static gchar *get_suffix_name_file(const gchar* allname)
4227 {
4228 	gchar *filename= g_path_get_basename(allname);
4229 	gchar *dirname= g_path_get_dirname(allname);
4230 	gchar *temp= g_strdup(filename);
4231 	gint len=strlen(filename);
4232 	gint i;
4233 	gchar* name = NULL;
4234 
4235 	if(!allname || strlen(allname)<1) return g_strdup("error");
4236 	filename= g_path_get_basename(allname);
4237 	dirname= g_path_get_dirname(allname);
4238 	temp= g_strdup(filename);
4239 	len=strlen(filename);
4240 
4241 	for(i=len;i>0;i--)
4242 	if(temp[i]=='.')
4243 	{
4244 		temp[i] = '\0';
4245 		break;
4246 	}
4247 	name = g_strdup_printf("%s%s%s",dirname,G_DIR_SEPARATOR_S,temp);
4248 	if(temp) g_free(temp);
4249 	if(dirname) g_free(dirname);
4250 	if(filename) g_free(filename);
4251 
4252 	if(strcmp(name,".")==0) name = g_strdup(g_get_current_dir());
4253 
4254 	return name;
4255 }
4256 /*************************************************************************************/
get_filename_png(const gchar * allname,gint i)4257 static gchar *get_filename_png(const gchar* allname, gint i)
4258 {
4259 	gchar *bas = get_suffix_name_file(allname);
4260 	if(bas)
4261 	{
4262 		gchar* fn = g_strdup_printf("%s_%d.png",bas,i);
4263 		g_free(bas);
4264 		return fn;
4265 	}
4266 	return g_strdup_printf("%d.png",i);
4267 }
4268 /****************************************************************************************/
gabedit_contoursplot_save_gabedit_images(GabeditContoursPlot * contoursplot,FILE * file,gchar * fileName)4269 static void gabedit_contoursplot_save_gabedit_images(GabeditContoursPlot *contoursplot, FILE* file, gchar* fileName)
4270 {
4271 	gint i;
4272 	gchar *fn;
4273 	fprintf(file,"images %d\n", contoursplot->nObjectsImage);
4274 	for(i=0;i<contoursplot->nObjectsImage;i++)
4275 	{
4276 		fprintf(file,"%lf %lf %lf %lf\n",
4277 				contoursplot->objectsImage[i].x,
4278 				contoursplot->objectsImage[i].y,
4279 				contoursplot->objectsImage[i].width,
4280 				contoursplot->objectsImage[i].height
4281 		       );
4282 		fn = get_filename_png(fileName, i);
4283 		fprintf(file,"%s\n", fn);
4284 		cairo_surface_write_to_png (contoursplot->objectsImage[i].image,fn);
4285 		g_free(fn);
4286 	}
4287 }
4288 /****************************************************************************************/
gabedit_contoursplot_save_gabedit_parameters(GabeditContoursPlot * contoursplot,FILE * file)4289 static void gabedit_contoursplot_save_gabedit_parameters(GabeditContoursPlot *contoursplot, FILE* file)
4290 {
4291 	GdkColor foreColor;
4292 	GdkColor backColor;
4293 	GdkGCValues gc_values;
4294 	GdkColormap *colormap;
4295 
4296 	colormap  = gdk_window_get_colormap(GTK_WIDGET(contoursplot)->window);
4297 	gdk_gc_get_values(contoursplot->back_gc, &gc_values);
4298        	gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&backColor);
4299 	gdk_gc_get_values(contoursplot->fore_gc, &gc_values);
4300        	gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&foreColor);
4301 
4302 	fprintf(file,"theme %d %d %d %d %d %d %d\n", gc_values.line_width,
4303 			(gint)foreColor.red, (gint)foreColor.green,(gint)foreColor.blue,
4304 			(gint)backColor.red, (gint)backColor.green,(gint)backColor.blue);
4305 	fprintf(file,"digits %d %d\n", contoursplot->x_legends_digits,  contoursplot->y_legends_digits);
4306 	fprintf(file,"ticks %d %d %d %d %d\n",  contoursplot->length_ticks,  contoursplot->hmajor_ticks, contoursplot->hminor_ticks,  contoursplot->vmajor_ticks, contoursplot->vminor_ticks);
4307 	fprintf(file,"margins %d %d %d %d\n",  contoursplot->left_margins,  contoursplot->top_margins, contoursplot->right_margins,  contoursplot->bottom_margins);
4308 	fprintf(file,"grid %d %d %d %d\n", contoursplot->hmajor_grid, contoursplot->hminor_grid, contoursplot->vmajor_grid, contoursplot->vminor_grid);
4309 	fprintf(file,"legends %d %d %d %d\n", contoursplot->show_left_legends, contoursplot->show_right_legends, contoursplot->show_top_legends, contoursplot->show_bottom_legends);
4310 	fprintf(file,"axes %d %d\n",  contoursplot->reflect_x, contoursplot->reflect_y);
4311 	fprintf(file,"fonts %d\n", contoursplot->font_size);
4312 	fprintf(file,"minmax %lf %lf %lf %lf\n",  contoursplot->xmin, contoursplot->xmax, contoursplot->ymin, contoursplot->ymax);
4313 	if(contoursplot->h_label_str)
4314 	{
4315 		fprintf(file,"hlabel 1\n");
4316 		fprintf(file,"%s\n",  contoursplot->h_label_str);
4317 	}
4318 	else fprintf(file,"hlabel 0\n");
4319 	if(contoursplot->v_label_str)
4320 	{
4321 		fprintf(file,"vlabel 1\n");
4322 		fprintf(file,"%s\n",  contoursplot->v_label_str);
4323 	}
4324 	else fprintf(file,"vlabel 0\n");
4325 
4326 }
4327 /****************************************************************************************/
gabedit_contoursplot_save_gabedit_contour(ContourData * contour,FILE * file)4328 static void gabedit_contoursplot_save_gabedit_contour(ContourData* contour, FILE* file)
4329 {
4330 	gint i;
4331 	fprintf(file,"contourline %lf %lf %lf %d %d\n",
4332 		SCALE(contour->line_color.red),
4333 		SCALE(contour->line_color.green),
4334 		SCALE(contour->line_color.blue),
4335 		contour->line_width,
4336 		contour->line_style);
4337 	fprintf(file,"contourpoint %lf %lf %lf %d %s\n",
4338 		SCALE(contour->point_color.red),
4339 		SCALE(contour->point_color.green),
4340 		SCALE(contour->point_color.blue),
4341 		contour->point_size,
4342 		contour->point_str);
4343 	fprintf(file,"size %d\n", contour->size);
4344 	fprintf(file,"value %lf\n", contour->value);
4345 	if(contour->label) fprintf(file,"label 1 %lf %lf %s\n", contour->xlabel, contour->ylabel, contour->label);
4346 	else fprintf(file,"label 0 0 0\n");
4347 	for(i=0;i<contour->size;i++)
4348 		fprintf(file,"%lf %lf %d\n", contour->x[i],contour->y[i],contour->index[i]);
4349 
4350 }
4351 /****************************************************************************************/
gabedit_contoursplot_save_gabedit_data(ContoursPlotData * data,FILE * file)4352 static void gabedit_contoursplot_save_gabedit_data(ContoursPlotData* data, FILE* file)
4353 {
4354 	gint i;
4355 	fprintf(file, "datax %d %lf %lf\n",data->xsize, data->xmin, data->xmax);
4356 	fprintf(file, "datay %d %lf %lf\n",data->ysize, data->ymin, data->ymax);
4357 	fprintf(file, "dataz %lf %lf\n", data->zmin, data->zmax);
4358 	for(i=0;i<data->xsize*data->ysize; i++)
4359 		fprintf(file, "%f\n",data->zValues[i]);
4360 	fprintf(file, "ncontours %d\n",data->nContours);
4361 	for(i=0;i<data->nContours; i++)
4362 		gabedit_contoursplot_save_gabedit_contour(&data->contours[i], file);
4363 }
4364 /****************************************************************************************/
gabedit_contoursplot_save_gabedit_datas(GabeditContoursPlot * contoursplot,FILE * file)4365 static void gabedit_contoursplot_save_gabedit_datas(GabeditContoursPlot *contoursplot, FILE* file)
4366 {
4367 	gint nDatas = 0;
4368 	ContoursPlotData* data;
4369 	GList *current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
4370 	for (; current_node!=NULL; current_node=current_node->next) nDatas++;
4371 	fprintf(file,"ndatas %d\n",nDatas);
4372 	if(nDatas<1) return;
4373 	current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
4374 	for (; current_node!=NULL; current_node=current_node->next)
4375 	{
4376 		data=(ContoursPlotData*)current_node->data;
4377 		gabedit_contoursplot_save_gabedit_data(data, file);
4378 	}
4379 }
4380 /****************************************************************************************/
gabedit_contoursplot_save_gabedit(GtkWidget * contoursplot,gchar * fileName)4381 static void gabedit_contoursplot_save_gabedit(GtkWidget* contoursplot, gchar* fileName)
4382 {
4383  	FILE* file = fopen(fileName, "w");
4384 	if(!file) return;
4385 	fprintf(file,"[Gabedit format]\n");
4386 	fprintf(file,"[ContoursPLOT]\n");
4387 	gabedit_contoursplot_save_gabedit_parameters(GABEDIT_ContoursPLOT(contoursplot), file);
4388 	gabedit_contoursplot_save_gabedit_texts(GABEDIT_ContoursPLOT(contoursplot), file);
4389 	gabedit_contoursplot_save_gabedit_lines(GABEDIT_ContoursPLOT(contoursplot), file);
4390 	gabedit_contoursplot_save_gabedit_images(GABEDIT_ContoursPLOT(contoursplot), file,fileName);
4391 	gabedit_contoursplot_save_gabedit_datas(GABEDIT_ContoursPLOT(contoursplot), file);
4392 	fclose(file);
4393 }
4394 /**************************************************************************/
saveAsGabedit(GtkFileChooser * SelecFile,gint response_id)4395 static void saveAsGabedit(GtkFileChooser *SelecFile, gint response_id)
4396 {
4397 	gchar *fileName;
4398 	GtkWidget* contoursplot = g_object_get_data (G_OBJECT (SelecFile), "ContoursPLOT");
4399 
4400  	if(response_id != GTK_RESPONSE_OK) return;
4401 	if(!GABEDIT_IS_ContoursPLOT(contoursplot)) return;
4402  	fileName = gtk_file_chooser_get_filename(SelecFile);
4403 	gabedit_contoursplot_save_gabedit(contoursplot, fileName);
4404 }
4405 /********************************************************************************/
saveAsGabeditDlg(GtkWidget * contoursplot)4406 static void saveAsGabeditDlg(GtkWidget* contoursplot)
4407 {
4408 	GtkFileFilter *filter;
4409 	GtkWidget *dialog;
4410 	GtkWidget *parentWindow;
4411 
4412 	dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_SAVE, "file-system-backend", "gtk+", "select-multiple", FALSE, NULL);
4413 	gtk_window_set_title (GTK_WINDOW (dialog), "Save as Gabedit format");
4414 	gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
4415 	filter = gtk_file_filter_new ();
4416 
4417 	gtk_file_filter_set_name (filter, "*.gab");
4418 	gtk_file_filter_add_pattern (filter, "*.gab");
4419 	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
4420 
4421 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
4422 	g_signal_connect (dialog, "response",  G_CALLBACK (saveAsGabedit),GTK_OBJECT(dialog));
4423 	g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy),GTK_OBJECT(dialog));
4424 	gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog),"contoursplot.gab");
4425 
4426 	g_object_set_data (G_OBJECT (dialog), "ContoursPLOT",contoursplot);
4427 	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4428 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
4429 	if(parentWindow) gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parentWindow));
4430 	gtk_widget_show(dialog);
4431 }
4432 /****************************************************************************************/
gabedit_contoursplot_read_gabedit_lines(GabeditContoursPlot * contoursplot,FILE * file)4433 static gboolean gabedit_contoursplot_read_gabedit_lines(GabeditContoursPlot *contoursplot, FILE* file)
4434 {
4435 	gint i;
4436 	gchar t[BSIZE];
4437 	gchar tmp[BSIZE];
4438 	gint style;
4439 	if(contoursplot->objectsLine)
4440 	{
4441 		g_free(contoursplot->objectsLine);
4442 		contoursplot->objectsLine = NULL;
4443 	}
4444     	if(!fgets(t,BSIZE,file)) return FALSE;
4445 	sscanf(t,"%s %d\n", tmp, &contoursplot->nObjectsLine);
4446 	if(contoursplot->nObjectsLine>0)
4447 		contoursplot->objectsLine = g_malloc(contoursplot->nObjectsLine*sizeof(ContoursPlotObjectLine));
4448 
4449 	for(i=0;i<contoursplot->nObjectsLine;i++)
4450 	{
4451 		gdouble r,g,b;
4452     		if(!fgets(t,BSIZE,file))
4453 		{
4454 			contoursplot->nObjectsLine= 0;
4455 			g_free(contoursplot->objectsLine);
4456 			contoursplot->objectsLine = NULL;
4457 			contoursplot->nObjectsLine = 0;
4458 		       	return FALSE;
4459 		}
4460 		sscanf(t,"%lf %lf %lf %lf %d %d %lf %lf %lf %d\n",
4461 				&contoursplot->objectsLine[i].x1,
4462 				&contoursplot->objectsLine[i].y1,
4463 				&contoursplot->objectsLine[i].x2,
4464 				&contoursplot->objectsLine[i].y2,
4465 				&contoursplot->objectsLine[i].width,
4466 				&contoursplot->objectsLine[i].arrow_size,
4467 				&r,&g,&b,
4468 				&style
4469 		       );
4470 		contoursplot->objectsLine[i].style = style;
4471 		contoursplot->objectsLine[i].color.red=SCALE2(r);
4472 		contoursplot->objectsLine[i].color.green=SCALE2(g);
4473 		contoursplot->objectsLine[i].color.blue=SCALE2(b);
4474 	}
4475 	reset_object_line_pixels(contoursplot);
4476 	return TRUE;
4477 }
4478 /****************************************************************************************/
gabedit_contoursplot_read_gabedit_texts(GabeditContoursPlot * contoursplot,FILE * file)4479 static gboolean gabedit_contoursplot_read_gabedit_texts(GabeditContoursPlot *contoursplot, FILE* file)
4480 {
4481 	gint i;
4482 	gchar t[BSIZE];
4483 	gchar tmp[BSIZE];
4484 	if(contoursplot->objectsText)
4485 	{
4486 		for(i=0;i<contoursplot->nObjectsText;i++)
4487 		{
4488 			if(contoursplot->objectsText[i].str) g_free(contoursplot->objectsText[i].str);
4489 			if(contoursplot->objectsText[i].pango) g_object_unref(contoursplot->objectsText[i].pango);
4490 		}
4491 		g_free(contoursplot->objectsText);
4492 		contoursplot->objectsText = NULL;
4493 		contoursplot->nObjectsText = 0;
4494 	}
4495     	if(!fgets(t,BSIZE,file)) return FALSE;
4496 	sscanf(t,"%s %d\n", tmp, &contoursplot->nObjectsText);
4497 	if(contoursplot->nObjectsText>0)
4498 	{
4499 		contoursplot->objectsText = g_malloc(contoursplot->nObjectsText*sizeof(ContoursPlotObjectText));
4500 		for(i=0;i<contoursplot->nObjectsText;i++) contoursplot->objectsText[i].str = NULL;
4501 	}
4502 	for(i=0;i<contoursplot->nObjectsText;i++)
4503 	{
4504     		if(!fgets(t,BSIZE,file))
4505 		{
4506 			for(i=0;i<contoursplot->nObjectsText;i++)
4507 				if(contoursplot->objectsText[i].str) g_free(contoursplot->objectsText[i].str);
4508 			contoursplot->nObjectsText= 0;
4509 			g_free(contoursplot->objectsText);
4510 			contoursplot->objectsText = NULL;
4511 		       	return FALSE;
4512 		}
4513 		sscanf(t,"%lf %lf %lf", &contoursplot->objectsText[i].x, &contoursplot->objectsText[i].y, &contoursplot->objectsText[i].angle);
4514     		if(fgets(t,BSIZE,file))
4515 		{
4516 			gint j;
4517 			for(j=0;j<strlen(t);j++) if(t[j]=='\n') t[j] = ' ';
4518 			contoursplot->objectsText[i].str= g_strdup(t);
4519 		}
4520 		else contoursplot->objectsText[i].str = g_strdup(" ");
4521 	}
4522 	for(i=0;i<contoursplot->nObjectsText;i++)
4523 	{
4524 		set_object_text_pango(contoursplot, &contoursplot->objectsText[i]);
4525 		set_object_text_pixels(contoursplot, &contoursplot->objectsText[i]);
4526 	}
4527 	return TRUE;
4528 }
4529 /****************************************************************************************/
gabedit_contoursplot_read_gabedit_images(GabeditContoursPlot * contoursplot,FILE * file)4530 static gboolean gabedit_contoursplot_read_gabedit_images(GabeditContoursPlot *contoursplot, FILE* file)
4531 {
4532 	gint i;
4533 	gchar t[BSIZE];
4534 	gchar tmp[BSIZE];
4535 	if(contoursplot->objectsImage)
4536 	{
4537 		for(i=0;i<contoursplot->nObjectsImage;i++)
4538 		{
4539 			if(contoursplot->objectsImage[i].fileName) g_free(contoursplot->objectsImage[i].fileName);
4540 			if(contoursplot->objectsImage[i].image) cairo_surface_destroy (contoursplot->objectsImage[i].image);
4541 		}
4542 		g_free(contoursplot->objectsImage);
4543 		contoursplot->objectsImage = NULL;
4544 		contoursplot->nObjectsImage = 0;
4545 	}
4546     	if(!fgets(t,BSIZE,file)) return FALSE;
4547 	sscanf(t,"%s %d\n", tmp, &contoursplot->nObjectsImage);
4548 	if(contoursplot->nObjectsImage>0)
4549 	{
4550 		contoursplot->objectsImage = g_malloc(contoursplot->nObjectsImage*sizeof(ContoursPlotObjectImage));
4551 		for(i=0;i<contoursplot->nObjectsImage;i++) contoursplot->objectsImage[i].fileName = NULL;
4552 		for(i=0;i<contoursplot->nObjectsImage;i++) contoursplot->objectsImage[i].image = NULL;
4553 	}
4554 	for(i=0;i<contoursplot->nObjectsImage;i++)
4555 	{
4556 		gdouble x,y,w,h;
4557     		if(!fgets(t,BSIZE,file))
4558 		{
4559 			for(i=0;i<contoursplot->nObjectsImage;i++)
4560 				if(contoursplot->objectsImage[i].fileName) g_free(contoursplot->objectsImage[i].fileName);
4561 			contoursplot->nObjectsImage= 0;
4562 			g_free(contoursplot->objectsImage);
4563 			contoursplot->objectsImage = NULL;
4564 		       	return FALSE;
4565 		}
4566 		sscanf(t,"%lf %lf %lf %lf", &x, &y, &w, &h);
4567 		contoursplot->objectsImage[i].x = x;
4568 		contoursplot->objectsImage[i].y = y;
4569 		contoursplot->objectsImage[i].width = w;
4570 		contoursplot->objectsImage[i].height = h;
4571     		if(fgets(t,BSIZE,file))
4572 		{
4573 			gint j;
4574 			gint len;
4575 			len = strlen(t);
4576 			for(j=0;j<strlen(t);j++)
4577 			{
4578 				if(t[j]=='\n') t[j] = ' ';
4579 				if(t[j]=='\r') t[j] = ' ';
4580 			}
4581 			len = strlen(t);
4582 			for(j=len;j>=0;j--)   if(t[j]==' ') t[j] = '\0';
4583 			contoursplot->objectsImage[i].fileName= g_strdup(t);
4584 		}
4585 		else contoursplot->objectsImage[i].fileName = g_strdup(" ");
4586 	}
4587 	for(i=0;i<contoursplot->nObjectsImage;i++)
4588 	{
4589 		contoursplot->objectsImage[i].image = cairo_image_surface_create_from_png (contoursplot->objectsImage[i].fileName);
4590 		if(!contoursplot->objectsImage[i].image)
4591 		{
4592 			printf("I cannot read %s png file\n",contoursplot->objectsImage[i].fileName);
4593 		}
4594 	}
4595 	reset_object_image_pixels(contoursplot);
4596 	return TRUE;
4597 }
4598 /****************************************************************************************/
gabedit_contoursplot_read_gabedit_parameters(GabeditContoursPlot * contoursplot,FILE * file)4599 static gboolean gabedit_contoursplot_read_gabedit_parameters(GabeditContoursPlot *contoursplot, FILE* file)
4600 {
4601 	gchar tmp[BSIZE];
4602 	gchar t[BSIZE];
4603 	gint i;
4604 	gint r1, g1, b1;
4605 	gint r2, g2, b2;
4606 	GdkColor foreColor;
4607 	GdkColor backColor;
4608 	gint line_width;
4609 
4610     	if(!fgets(t,BSIZE,file)) return FALSE;
4611 	sscanf(t,"%s %d %d %d %d %d %d %d", tmp, &line_width, &r1, &g1, &b1, &r2, &g2, &b2);
4612 	foreColor.red = (gushort)r1;
4613 	foreColor.green = (gushort)g1;
4614 	foreColor.blue = (gushort)b1;
4615 	backColor.red = (gushort)r2;
4616 	backColor.green = (gushort)g2;
4617 	backColor.blue = (gushort)b2;
4618 
4619     	if(!fgets(t,BSIZE,file)) return FALSE;
4620 	sscanf(t,"%s %d %d", tmp, &contoursplot->x_legends_digits,  &contoursplot->y_legends_digits);
4621     	if(!fgets(t,BSIZE,file)) return FALSE;
4622 	sscanf(t,"%s %d %d %d %d %d",  tmp, &contoursplot->length_ticks,  &contoursplot->hmajor_ticks, &contoursplot->hminor_ticks,  &contoursplot->vmajor_ticks, &contoursplot->vminor_ticks);
4623     	if(!fgets(t,BSIZE,file)) return FALSE;
4624 	sscanf(t,"%s %d %d %d %d",  tmp, &contoursplot->left_margins,  &contoursplot->top_margins, &contoursplot->right_margins,  &contoursplot->bottom_margins);
4625     	if(!fgets(t,BSIZE,file)) return FALSE;
4626 	sscanf(t,"%s %d %d %d %d", tmp, &contoursplot->hmajor_grid, &contoursplot->hminor_grid, &contoursplot->vmajor_grid, &contoursplot->vminor_grid);
4627 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMAJOR_GRID, contoursplot->hmajor_grid);
4628 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMINOR_GRID, contoursplot->hminor_grid);
4629 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMAJOR_GRID, contoursplot->vmajor_grid);
4630 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMINOR_GRID, contoursplot->vminor_grid);
4631     	if(!fgets(t,BSIZE,file)) return FALSE;
4632 	sscanf(t,"%s %d %d %d %d", tmp, &contoursplot->show_left_legends, &contoursplot->show_right_legends, &contoursplot->show_top_legends, &contoursplot->show_bottom_legends);
4633 	gabedit_contoursplot_show_left_legends (GABEDIT_ContoursPLOT(contoursplot), contoursplot->show_left_legends);
4634 	gabedit_contoursplot_show_right_legends (GABEDIT_ContoursPLOT(contoursplot), contoursplot->show_right_legends);
4635 	gabedit_contoursplot_show_top_legends (GABEDIT_ContoursPLOT(contoursplot), contoursplot->show_top_legends);
4636 	gabedit_contoursplot_show_bottom_legends (GABEDIT_ContoursPLOT(contoursplot), contoursplot->show_bottom_legends);
4637     	if(!fgets(t,BSIZE,file)) return FALSE;
4638 	sscanf(t,"%s %d %d",  tmp, &contoursplot->reflect_x, &contoursplot->reflect_y);
4639 	gabedit_contoursplot_reflect_x (GABEDIT_ContoursPLOT(contoursplot), contoursplot->reflect_x);
4640 	gabedit_contoursplot_reflect_y (GABEDIT_ContoursPLOT(contoursplot), contoursplot->reflect_y);
4641     	if(!fgets(t,BSIZE,file)) return FALSE;
4642 	sscanf(t,"%s %d", tmp, &contoursplot->font_size);
4643     	if(!fgets(t,BSIZE,file)) return FALSE;
4644 	sscanf(t,"%s %lf %lf %lf %lf", tmp, &contoursplot->xmin, &contoursplot->xmax, &contoursplot->ymin, &contoursplot->ymax);
4645 
4646 	if(contoursplot->h_label_str) g_free(contoursplot->h_label_str);
4647 	if(contoursplot->v_label_str) g_free(contoursplot->v_label_str);
4648 	contoursplot->h_label_str = NULL;
4649 	contoursplot->v_label_str = NULL;
4650     	if(!fgets(t,BSIZE,file)) return FALSE;
4651 	sscanf(t,"%s %d",tmp,&i);
4652 	if(i!=0)
4653 	{
4654 		gint j;
4655     		if(!fgets(t,BSIZE,file)) return FALSE;
4656 		for(j=0;j<strlen(t);j++) if(t[j]=='\n') t[j] = ' ';
4657 		contoursplot->h_label_str = g_strdup(t);
4658 	}
4659     	if(!fgets(t,BSIZE,file)) return FALSE;
4660 	sscanf(t,"%s %d",tmp,&i);
4661 	if(i!=0)
4662 	{
4663 		gint j;
4664     		if(!fgets(t,BSIZE,file)) return FALSE;
4665 		for(j=0;j<strlen(t);j++) if(t[j]=='\n') t[j] = ' ';
4666 		contoursplot->v_label_str = g_strdup(t);
4667 	}
4668 	contoursplot_build_legends(contoursplot);
4669 	contoursplot_calculate_legends_sizes(contoursplot);
4670 	contoursplot_calculate_sizes(contoursplot);
4671 	reset_theme(GTK_WIDGET(contoursplot), line_width, &foreColor, &backColor);
4672 	return TRUE;
4673 
4674 }
4675 /****************************************************************************************/
gabedit_contoursplot_read_gabedit_contour(ContourData * contour,FILE * file)4676 static gboolean gabedit_contoursplot_read_gabedit_contour(ContourData* contour, FILE* file)
4677 {
4678 	gint i;
4679 	gchar tmp[BSIZE];
4680 	gchar t[BSIZE];
4681 	gdouble r,g,b;
4682 	gint style;
4683 	contour->size = 0;
4684 	contour->x = NULL;
4685 	contour->y = NULL;
4686 	contour->index = NULL;
4687 	contour->point_pango = NULL;
4688     	if(!fgets(t,BSIZE,file)) return FALSE;
4689 	sscanf(t,"%s %lf %lf %lf %d %d",
4690 		tmp,
4691 		&r,&g,&b,
4692 		&contour->line_width,
4693 		&style);
4694 	contour->line_style = style;
4695 	contour->line_color.red = SCALE2(r);
4696 	contour->line_color.green = SCALE2(g);
4697 	contour->line_color.blue = SCALE2(b);
4698     	if(!fgets(t,BSIZE,file)) return FALSE;
4699 	sscanf(t,"%s %lf %lf %lf %d %s",
4700 		tmp,
4701 		&r,&g,&b,
4702 		&contour->point_size,
4703 		contour->point_str);
4704 	contour->point_color.red = SCALE2(r);
4705 	contour->point_color.green = SCALE2(g);
4706 	contour->point_color.blue = SCALE2(b);
4707     	if(!fgets(t,BSIZE,file)) return FALSE;
4708 	sscanf(t,"%s %d", tmp, &contour->size);
4709 	if(contour->size<1) return TRUE;
4710     	if(!fgets(t,BSIZE,file)) return FALSE;
4711 	sscanf(t,"%s %lf", tmp, &contour->value);
4712 
4713     	if(!fgets(t,BSIZE,file)) return FALSE;
4714 	sscanf(t,"%s %d",tmp,&i);
4715 	contour->label = NULL;
4716 	contour->xlabel = 0;
4717 	contour->ylabel = 0;
4718 	if(i!=0)
4719 	{
4720 		contour->label = g_strdup(t);
4721 		sscanf(t,"%s %d %lf %lf %s",tmp,&i,&contour->xlabel, &contour->ylabel, contour->label);
4722 	}
4723 	contour->x = g_malloc(contour->size*sizeof(gdouble));
4724 	contour->y = g_malloc(contour->size*sizeof(gdouble));
4725 	contour->index = g_malloc(contour->size*sizeof(gint));
4726 	for(i=0;i<contour->size;i++)
4727 	{
4728     		if(!fgets(t,BSIZE,file))
4729 		{
4730 			contour->size = 0;
4731 			if(contour->x) g_free(contour->x);
4732 			if(contour->y) g_free(contour->y);
4733 			if(contour->index) g_free(contour->index);
4734 			contour->x = NULL;
4735 			contour->y = NULL;
4736 			contour->index = NULL;
4737 			return FALSE;
4738 		}
4739 
4740 		sscanf(t,"%lf %lf %d", &contour->x[i],&contour->y[i], &contour->index[i]);
4741 	}
4742 	return TRUE;
4743 }
4744 /****************************************************************************************/
gabedit_contoursplot_read_gabedit_data(ContoursPlotData * data,FILE * file)4745 static gboolean gabedit_contoursplot_read_gabedit_data(ContoursPlotData* data, FILE* file)
4746 {
4747 	gint i;
4748 	gchar tmp[BSIZE];
4749 	gchar t[BSIZE];
4750 	gboolean Ok = TRUE;
4751 	data->xsize = 0;
4752 	data->ysize = 0;
4753 	data->zValues = NULL;
4754     	if(!fgets(t,BSIZE,file)) return FALSE;
4755 	sscanf(t, "%s %d %lf %lf",tmp, &data->xsize, &data->xmin, &data->xmax);
4756     	if(!fgets(t,BSIZE,file)) return FALSE;
4757 	sscanf(t, "%s %d %lf %lf",tmp, &data->ysize, &data->ymin, &data->ymax);
4758     	if(!fgets(t,BSIZE,file)) return FALSE;
4759 	sscanf(t, "%s %lf %lf",tmp, &data->zmin, &data->zmax);
4760 	if( data->xsize <1) return FALSE;
4761 	if( data->ysize <1) return FALSE;
4762 	data->zValues = g_malloc(data->xsize*data->ysize*sizeof(gdouble));
4763 	for(i=0;i<data->xsize*data->ysize; i++)
4764 	{
4765     		if(!fgets(t,BSIZE,file)) return FALSE;
4766 		sscanf(t, "%lf",&data->zValues[i]);
4767 	}
4768 	data->nContours = 0;
4769 	data->contours = NULL;
4770     	if(!fgets(t,BSIZE,file)) return FALSE;
4771 	sscanf(t, "%s %d\n",tmp, &data->nContours);
4772 	if(data->nContours<1) return TRUE;
4773 	data->contours = g_malloc(data->nContours*sizeof(ContourData));
4774 
4775 	for(i=0;i<data->nContours; i++)
4776 	{
4777 		Ok = gabedit_contoursplot_read_gabedit_contour(&data->contours[i], file);
4778 		if(!Ok) break;
4779 	}
4780 	if(!Ok)
4781 	{
4782 		g_free(data->contours);
4783 		data->contours = NULL;
4784 		data->nContours = 0;
4785 	}
4786 	return Ok;
4787 }
4788 /****************************************************************************************/
gabedit_contoursplot_read_gabedit_datas(GabeditContoursPlot * contoursplot,FILE * file)4789 static gboolean gabedit_contoursplot_read_gabedit_datas(GabeditContoursPlot *contoursplot, FILE* file)
4790 {
4791 	gint nDatas = 0;
4792 	gchar tmp[BSIZE];
4793 	gchar t[BSIZE];
4794 	gint i;
4795 
4796     	if(!fgets(t,BSIZE,file)) return FALSE;
4797 	sscanf(t,"%s %d",tmp, &nDatas);
4798 	if(nDatas<1) return TRUE;
4799 	if(GABEDIT_ContoursPLOT(contoursplot)->data_list)
4800 	{
4801 		g_list_foreach(GABEDIT_ContoursPLOT(contoursplot)->data_list, (GFunc)g_free, NULL);
4802 		g_list_free(GABEDIT_ContoursPLOT(contoursplot)->data_list);
4803 		GABEDIT_ContoursPLOT(contoursplot)->data_list = NULL;
4804 	}
4805 	for(i=0;i<nDatas;i++)
4806 	{
4807 		ContoursPlotData *data = g_malloc(sizeof(ContoursPlotData));
4808 		if(!gabedit_contoursplot_read_gabedit_data(data, file)) return FALSE;
4809 		if(data&& data->xsize>0 && data->ysize>0 && data->zValues)
4810 		{
4811 			gabedit_contoursplot_add_data (GABEDIT_ContoursPLOT(contoursplot), data);
4812 		}
4813 	}
4814 	return TRUE;
4815 }
4816 /****************************************************************************************/
gabedit_contoursplot_read_gabedit(GtkWidget * contoursplot,gchar * fileName)4817 static gboolean gabedit_contoursplot_read_gabedit(GtkWidget* contoursplot, gchar* fileName)
4818 {
4819 	gchar t[BSIZE];
4820  	FILE* file = fopen(fileName, "rb");
4821 	if(!file) return FALSE;
4822     	if(!fgets(t,BSIZE,file)) return FALSE;
4823 	uppercase(t);
4824 	if(!strstr(t,"[GABEDIT FORMAT]"))
4825 	{
4826 		contoursplot_message(_("This is not a Gabedit file\n"));
4827 		fclose(file);
4828 		return FALSE;
4829 	}
4830 	while(!feof(file))
4831 	{
4832     		if(!fgets(t,BSIZE,file))
4833 		{
4834 			fclose(file);
4835 			return FALSE;
4836 		}
4837 		if(strstr(t,"[ContoursPLOT]"))
4838 		{
4839 			delete_objects_text(contoursplot);
4840 			delete_objects_line(contoursplot);
4841 			delete_contours(contoursplot,NULL);
4842 			if(GABEDIT_ContoursPLOT(contoursplot)->data_list)
4843 			{
4844 				g_list_foreach(GABEDIT_ContoursPLOT(contoursplot)->data_list, (GFunc)g_free, NULL);
4845 				g_list_free(GABEDIT_ContoursPLOT(contoursplot)->data_list);
4846 				GABEDIT_ContoursPLOT(contoursplot)->data_list = NULL;
4847 			}
4848 			gabedit_contoursplot_read_gabedit_parameters(GABEDIT_ContoursPLOT(contoursplot), file);
4849 			gabedit_contoursplot_read_gabedit_texts(GABEDIT_ContoursPLOT(contoursplot), file);
4850 			gabedit_contoursplot_read_gabedit_lines(GABEDIT_ContoursPLOT(contoursplot), file);
4851 			gabedit_contoursplot_read_gabedit_images(GABEDIT_ContoursPLOT(contoursplot), file);
4852 			gabedit_contoursplot_read_gabedit_datas(GABEDIT_ContoursPLOT(contoursplot), file);
4853 			reset_color_map(contoursplot, NULL);
4854 			fclose(file);
4855 			return TRUE;
4856 		}
4857 	}
4858 	contoursplot_message(_("I can not read the ContoursPlot data\n"));
4859 	fclose(file);
4860 	return FALSE;
4861 }
4862 /**************************************************************************/
readAGabedit(GtkFileChooser * SelecFile,gint response_id)4863 static void readAGabedit(GtkFileChooser *SelecFile, gint response_id)
4864 {
4865 	gchar *fileName;
4866 	GtkWidget* contoursplot = g_object_get_data (G_OBJECT (SelecFile), "ContoursPLOT");
4867 
4868  	if(response_id != GTK_RESPONSE_OK) return;
4869 	if(!GABEDIT_IS_ContoursPLOT(contoursplot)) return;
4870  	fileName = gtk_file_chooser_get_filename(SelecFile);
4871 	gabedit_contoursplot_read_gabedit(contoursplot, fileName);
4872 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
4873 }
4874 /********************************************************************************/
readAGabeditDlg(GtkWidget * contoursplot)4875 static void readAGabeditDlg(GtkWidget* contoursplot)
4876 {
4877 	GtkFileFilter *filter;
4878 	GtkWidget *dialog;
4879 	GtkWidget *parentWindow;
4880 
4881 	dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_OPEN, "file-system-backend", "gtk+", "select-multiple", FALSE, NULL);
4882 	gtk_window_set_title (GTK_WINDOW (dialog), "Read a Gabedit file");
4883 	gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
4884 
4885 	filter = gtk_file_filter_new ();
4886 
4887 	gtk_file_filter_set_name (filter, "*.gab");
4888 	gtk_file_filter_add_pattern (filter, "*.gab");
4889 	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
4890 
4891 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
4892 	g_signal_connect (dialog, "response",  G_CALLBACK (readAGabedit),GTK_OBJECT(dialog));
4893 	g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy),GTK_OBJECT(dialog));
4894 
4895 	g_object_set_data (G_OBJECT (dialog), "ContoursPLOT",contoursplot);
4896 	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4897 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
4898 	if(parentWindow) gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parentWindow));
4899 	gtk_widget_show(dialog);
4900 }
4901 /*************************************************************************************/
Waiting(gdouble tsecond)4902 static void Waiting(gdouble tsecond)
4903 {
4904         GTimer *timer;
4905         gdouble elaps;
4906         gulong m ;
4907 
4908         timer =g_timer_new( );
4909 	g_timer_start( timer );
4910 	g_timer_reset( timer );
4911         do{
4912 		elaps = g_timer_elapsed( timer,&m);
4913         }while(elaps<tsecond);
4914  	g_timer_destroy(timer);
4915 }
4916 /**************************************************************************/
copyImageToClipBoard(GtkWidget * contoursplot)4917 static void copyImageToClipBoard(GtkWidget* contoursplot)
4918 {
4919 	if(!GABEDIT_IS_ContoursPLOT(contoursplot)) return;
4920 	gtk_widget_hide(contoursplot);
4921 	gtk_widget_show(contoursplot);
4922 	while( gtk_events_pending() ) gtk_main_iteration();
4923 
4924 	gabedit_contoursplot_save_image(GABEDIT_ContoursPLOT(contoursplot), NULL, NULL);
4925 }
4926 /**************************************************************************/
saveImage(GtkFileChooser * SelecFile,gint response_id)4927 static void saveImage(GtkFileChooser *SelecFile, gint response_id)
4928 {
4929 	gchar *fileName;
4930 	GtkWidget* contoursplot = g_object_get_data (G_OBJECT (SelecFile), "ContoursPLOT");
4931 	gchar* type = g_object_get_data (G_OBJECT (SelecFile), "ImageType");
4932 
4933  	if(response_id != GTK_RESPONSE_OK) return;
4934 
4935  	fileName = gtk_file_chooser_get_filename(SelecFile);
4936 	gtk_widget_hide(GTK_WIDGET(SelecFile));
4937 	while( gtk_events_pending() ) gtk_main_iteration();
4938 	Waiting(1.0);
4939 
4940 	if(!GABEDIT_IS_ContoursPLOT(contoursplot)) return;
4941 	gtk_widget_hide(contoursplot);
4942 	gtk_widget_show(contoursplot);
4943 	while( gtk_events_pending() ) gtk_main_iteration();
4944 
4945 	gabedit_contoursplot_save_image(GABEDIT_ContoursPLOT(contoursplot), fileName, type);
4946 }
4947 /********************************************************************************/
saveImageDlg(GtkWidget * contoursplot,gchar * type)4948 static void saveImageDlg(GtkWidget* contoursplot, gchar* type)
4949 {
4950 	GtkFileFilter *filter;
4951 	GtkWidget *dialog;
4952 	gchar* tmp = NULL;
4953 	GtkWidget *parentWindow;
4954 
4955 	dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_SAVE, "file-system-backend", "gtk+", "select-multiple", FALSE, NULL);
4956 	gtk_window_set_title (GTK_WINDOW (dialog), _("Save Contours plot"));
4957 	gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
4958 	filter = gtk_file_filter_new ();
4959 
4960 	tmp = g_strdup_printf("*.%s",type);
4961 	gtk_file_filter_set_name (filter, tmp);
4962 	gtk_file_filter_add_pattern (filter, tmp);
4963 	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
4964 	g_free(tmp);
4965 
4966 
4967 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
4968 	g_signal_connect (dialog, "response",  G_CALLBACK (saveImage),GTK_OBJECT(dialog));
4969 	g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy),GTK_OBJECT(dialog));
4970 	g_object_set_data(G_OBJECT (dialog), "ImageType", type);
4971 	if(!strcmp(type,"tpng"))
4972 		tmp = g_strdup_printf("contoursplot.png");
4973 	else
4974 		tmp = g_strdup_printf("contoursplot.%s",type);
4975 	gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog),tmp);
4976 	g_free(tmp);
4977 
4978 	g_object_set_data (G_OBJECT (dialog), "ContoursPLOT",contoursplot);
4979 	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4980 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
4981 	if(parentWindow) gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parentWindow));
4982 	gtk_widget_show(dialog);
4983 }
4984 /*****************************************************************************/
gabedit_contoursplot_export(GabeditContoursPlot * contoursplot,gchar * fileName,gchar * fileType)4985 static void gabedit_contoursplot_export(GabeditContoursPlot *contoursplot, gchar* fileName, gchar* fileType)
4986 {
4987 	GtkWidget* widget = NULL;
4988   	g_return_if_fail (contoursplot != NULL);
4989   	g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
4990   	g_return_if_fail (fileName != NULL);
4991   	g_return_if_fail (fileType != NULL);
4992 	widget = GTK_WIDGET(contoursplot);
4993 	if(!strcmp(fileType,"pdf"))
4994 	{
4995 
4996 		cairo_surface_t *surface;
4997 		surface = cairo_pdf_surface_create(fileName, widget->allocation.width, widget->allocation.height);
4998 		contoursplot->cairo_export = cairo_create(surface);
4999 		gabedit_contoursplot_draw (widget);
5000 		cairo_show_page(contoursplot->cairo_export);
5001 		cairo_surface_destroy(surface);
5002 		cairo_destroy(contoursplot->cairo_export);
5003 		contoursplot->cairo_export = NULL;
5004 		return;
5005 	}
5006 	else
5007 	if(!strcmp(fileType,"ps"))
5008 	{
5009 
5010 		cairo_surface_t *surface;
5011 		surface = cairo_ps_surface_create(fileName, widget->allocation.width, widget->allocation.height);
5012 		contoursplot->cairo_export = cairo_create(surface);
5013 		gabedit_contoursplot_draw (widget);
5014 		cairo_show_page(contoursplot->cairo_export);
5015 		cairo_surface_destroy(surface);
5016 		cairo_destroy(contoursplot->cairo_export);
5017 		contoursplot->cairo_export = NULL;
5018 		return;
5019 	}
5020 	else
5021 	if(!strcmp(fileType,"eps"))
5022 	{
5023 
5024 		cairo_surface_t *surface;
5025 		surface = cairo_ps_surface_create(fileName, widget->allocation.width, widget->allocation.height);
5026 		cairo_ps_surface_set_eps(surface, TRUE);
5027 		contoursplot->cairo_export = cairo_create(surface);
5028 		gabedit_contoursplot_draw (widget);
5029 		cairo_show_page(contoursplot->cairo_export);
5030 		cairo_surface_destroy(surface);
5031 		cairo_destroy(contoursplot->cairo_export);
5032 		contoursplot->cairo_export = NULL;
5033 		return;
5034 	}
5035 	else
5036 	if(!strcmp(fileType,"svg"))
5037 	{
5038 
5039 		cairo_surface_t *surface;
5040 		surface = cairo_svg_surface_create(fileName, widget->allocation.width, widget->allocation.height);
5041 		contoursplot->cairo_export = cairo_create(surface);
5042 		gabedit_contoursplot_draw (widget);
5043 		cairo_show_page(contoursplot->cairo_export);
5044 		cairo_surface_destroy(surface);
5045 		cairo_destroy(contoursplot->cairo_export);
5046 		contoursplot->cairo_export = NULL;
5047 		return;
5048 	}
5049 }
5050 /**************************************************************************/
exportImage(GtkFileChooser * SelecFile,gint response_id)5051 static void exportImage(GtkFileChooser *SelecFile, gint response_id)
5052 {
5053 	gchar *fileName;
5054 	GtkWidget* contoursplot = g_object_get_data (G_OBJECT (SelecFile), "ContoursPLOT");
5055 	gchar* type = g_object_get_data (G_OBJECT (SelecFile), "ImageType");
5056 
5057  	if(response_id != GTK_RESPONSE_OK) return;
5058 
5059  	fileName = gtk_file_chooser_get_filename(SelecFile);
5060 	gtk_widget_hide(GTK_WIDGET(SelecFile));
5061 	while( gtk_events_pending() ) gtk_main_iteration();
5062 	Waiting(1.0);
5063 
5064 	if(!GABEDIT_IS_ContoursPLOT(contoursplot)) return;
5065 	gtk_widget_hide(contoursplot);
5066 	gtk_widget_show(contoursplot);
5067 	while( gtk_events_pending() ) gtk_main_iteration();
5068 
5069 	gabedit_contoursplot_export(GABEDIT_ContoursPLOT(contoursplot), fileName, type);
5070 }
5071 /********************************************************************************/
exportImageDlg(GtkWidget * contoursplot,gchar * type)5072 static void exportImageDlg(GtkWidget* contoursplot, gchar* type)
5073 {
5074 	GtkFileFilter *filter;
5075 	GtkWidget *dialog;
5076 	gchar* tmp = NULL;
5077 	GtkWidget *parentWindow;
5078 
5079 	dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_SAVE, "file-system-backend", "gtk+", "select-multiple", FALSE, NULL);
5080 	gtk_window_set_title (GTK_WINDOW (dialog), _("Export Contours plot"));
5081 	gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
5082 	filter = gtk_file_filter_new ();
5083 
5084 	tmp = g_strdup_printf("*.%s",type);
5085 	gtk_file_filter_set_name (filter, tmp);
5086 	gtk_file_filter_add_pattern (filter, tmp);
5087 	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
5088 	g_free(tmp);
5089 
5090 
5091 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
5092 	g_signal_connect (dialog, "response",  G_CALLBACK (exportImage),GTK_OBJECT(dialog));
5093 	g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy),GTK_OBJECT(dialog));
5094 	g_object_set_data(G_OBJECT (dialog), "ImageType", type);
5095 	tmp = g_strdup_printf("gabeditExport.%s",type);
5096 	gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog),tmp);
5097 	g_free(tmp);
5098 
5099 	g_object_set_data (G_OBJECT (dialog), "ContoursPLOT",contoursplot);
5100 	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5101 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
5102 	if(parentWindow) gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parentWindow));
5103 	gtk_widget_show(dialog);
5104 }
5105 /********************************************************************************/
activate_entry_label_contour_str(GtkWidget * entry,gpointer user_data)5106 static void activate_entry_label_contour_str(GtkWidget *entry, gpointer user_data)
5107 {
5108 	G_CONST_RETURN gchar* t;
5109 	GtkWidget* contoursplot = NULL;
5110 	ContourData* contour = NULL;
5111 
5112 
5113 	if(!user_data || !G_IS_OBJECT(user_data)) return;
5114 	contoursplot = GTK_WIDGET(user_data);
5115 	t= gtk_entry_get_text(GTK_ENTRY(entry));
5116 	contour = g_object_get_data(G_OBJECT (entry), "CurentContour");
5117 	if(contour->label) g_free(contour->label);
5118 	contour->label = g_strdup(t);
5119 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5120 }
5121 /********************************************************************************/
activate_entry_label_contour_x(GtkWidget * entry,gpointer user_data)5122 static void activate_entry_label_contour_x(GtkWidget *entry, gpointer user_data)
5123 {
5124 	G_CONST_RETURN gchar* t;
5125 	GtkWidget* contoursplot = NULL;
5126 	ContourData* contour = NULL;
5127 
5128 
5129 	if(!user_data || !G_IS_OBJECT(user_data)) return;
5130 	contoursplot = GTK_WIDGET(user_data);
5131 	t= gtk_entry_get_text(GTK_ENTRY(entry));
5132 	contour = g_object_get_data(G_OBJECT (entry), "CurentContour");
5133 	contour->xlabel = atof(t);
5134 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5135 }
5136 /********************************************************************************/
activate_entry_label_contour_y(GtkWidget * entry,gpointer user_data)5137 static void activate_entry_label_contour_y(GtkWidget *entry, gpointer user_data)
5138 {
5139 	G_CONST_RETURN gchar* t;
5140 	GtkWidget* contoursplot = NULL;
5141 	ContourData* contour = NULL;
5142 
5143 
5144 	if(!user_data || !G_IS_OBJECT(user_data)) return;
5145 	contoursplot = GTK_WIDGET(user_data);
5146 	t= gtk_entry_get_text(GTK_ENTRY(entry));
5147 	contour = g_object_get_data(G_OBJECT (entry), "CurentContour");
5148 	contour->ylabel = atof(t);
5149 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5150 }
5151 /****************************************************************************************/
spin_line_width_changed_value(GtkSpinButton * spinbutton,gpointer user_data)5152 static void spin_line_width_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
5153 {
5154 	if(user_data && G_IS_OBJECT(user_data))
5155 	{
5156 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5157 		ContourData* contour = g_object_get_data(G_OBJECT (spinbutton), "CurentContour");
5158   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5159 		if(contour) contour->line_width = gtk_spin_button_get_value(spinbutton);
5160 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5161 	}
5162 }
5163 /****************************************************************************************/
spin_line_color_changed_value(GtkColorButton * colorbutton,gpointer user_data)5164 static void spin_line_color_changed_value(GtkColorButton  *colorbutton, gpointer user_data)
5165 {
5166 	if(user_data && G_IS_OBJECT(user_data))
5167 	{
5168 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5169 		ContourData* contour = g_object_get_data(G_OBJECT (colorbutton), "CurentContour");
5170 		GdkColor c;
5171 		gtk_color_button_get_color (colorbutton, &c);
5172 
5173   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5174 
5175 		if(contour) contour->line_color = c;
5176 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5177 	}
5178 }
5179 /********************************************************************************************************/
combo_line_style_changed_value(GtkComboBox * combobox,gpointer user_data)5180 static void combo_line_style_changed_value (GtkComboBox *combobox, gpointer user_data)
5181 {
5182 	GtkTreeIter iter;
5183 	gchar* d = NULL;
5184 
5185 	if (gtk_combo_box_get_active_iter (combobox, &iter))
5186 	{
5187 		GtkTreeModel* model = gtk_combo_box_get_model(combobox);
5188 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5189 		ContourData* contour = g_object_get_data(G_OBJECT (combobox), "CurentContour");
5190 
5191   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5192 
5193 		gtk_tree_model_get (model, &iter, 0, &d, -1);
5194 		if(!d) return;
5195 		if(contour)
5196 		{
5197 		if (!strcmp(d,"Solid") ) {  contour->line_style = GDK_LINE_SOLID; }
5198 		else if (!strcmp(d,"On-Off dashed") ) {contour->line_style = GDK_LINE_ON_OFF_DASH; }
5199 		else if (!strcmp(d,"Double dashed") ) { contour->line_style = GDK_LINE_DOUBLE_DASH;}
5200 		}
5201 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5202 	}
5203 }
5204 /****************************************************************************************/
spin_point_size_changed_value(GtkSpinButton * spinbutton,gpointer user_data)5205 static void spin_point_size_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
5206 {
5207 	if(user_data && G_IS_OBJECT(user_data))
5208 	{
5209 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5210 		ContourData* contour = g_object_get_data(G_OBJECT (spinbutton), "CurentContour");
5211 
5212   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5213 
5214 		if(contour)
5215 		{
5216 			contour->point_size = gtk_spin_button_get_value(spinbutton);
5217 			contoursplot_build_points_contour(GABEDIT_ContoursPLOT(contoursplot), contour);
5218 		}
5219 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5220 	}
5221 }
5222 /********************************************************************************************************/
combo_point_style_changed_value(GtkComboBox * combobox,gpointer user_data)5223 static void combo_point_style_changed_value (GtkComboBox *combobox, gpointer user_data)
5224 {
5225 	GtkTreeIter iter;
5226 	gchar* d = NULL;
5227 
5228 	if (gtk_combo_box_get_active_iter (combobox, &iter))
5229 	{
5230 		GtkTreeModel* model = gtk_combo_box_get_model(combobox);
5231 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5232 		ContourData* contour = g_object_get_data(G_OBJECT (combobox), "CurentContour");
5233 
5234   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5235 
5236 		gtk_tree_model_get (model, &iter, 0, &d, -1);
5237 		if(!d) return;
5238 		if(contour)
5239 		{
5240 			sprintf(contour->point_str,"%s",d);
5241 			contoursplot_build_points_contour(GABEDIT_ContoursPLOT(contoursplot), contour);
5242 		}
5243 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5244 	}
5245 }
5246 /****************************************************************************************/
spin_point_color_changed_value(GtkColorButton * colorbutton,gpointer user_data)5247 static void spin_point_color_changed_value(GtkColorButton  *colorbutton, gpointer user_data)
5248 {
5249 	if(user_data && G_IS_OBJECT(user_data))
5250 	{
5251 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5252 		ContourData* contour = g_object_get_data(G_OBJECT (colorbutton), "CurentContour");
5253 		GdkColor c;
5254 
5255   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5256 
5257 		gtk_color_button_get_color (colorbutton, &c);
5258 
5259 		if(contour)
5260 		{
5261 			contour->point_color = c;
5262 			contoursplot_build_points_contour(GABEDIT_ContoursPLOT(contoursplot), contour);
5263 		}
5264 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5265 	}
5266 }
5267 /********************************************************************************************************/
add_point_types_combo(GtkWidget * hbox,ContourData * contour)5268 static GtkWidget *add_point_types_combo(GtkWidget *hbox, ContourData* contour)
5269 {
5270         GtkTreeIter iter;
5271         GtkTreeStore *store;
5272 	GtkTreeModel *model;
5273 	GtkWidget *combobox;
5274 	GtkCellRenderer *renderer;
5275 	gint i = 0;
5276 	gint k = 0;
5277 	/* 0x2605=star, 25C6=BLACK DIAMOND,  0x25B2= black triangle, 0x25B3=white triangle */
5278 	/* long int x =0x2605; printf("%d\n",x) in decimal*/
5279 	gchar* list [] = {"<span>&#9733;</span>","+","x",
5280 		"<span>&#9675;</span>", "<span>&#9679;</span>",
5281 		"<span>&#9688;</span>", "<span>&#9689;</span>",
5282 		"<span>&#9670;</span>", "<span>&#9674;</span>",
5283 		"<span>&#8226;</span>",
5284 		"<span><b>&#9788;</b></span>",
5285 		"<span>&#9651;</span>", "<span>&#9650;</span>"};
5286 	gint n = G_N_ELEMENTS (list);
5287 
5288 	store = gtk_tree_store_new (1,G_TYPE_STRING);
5289 
5290 	for(i=0;i<n;i++)
5291 	{
5292         	gtk_tree_store_append (store, &iter, NULL);
5293         	gtk_tree_store_set (store, &iter, 0, list[i], -1);
5294 		if(!strcmp(list[i],contour->point_str)) k = i;
5295 	}
5296 
5297 
5298         model = GTK_TREE_MODEL (store);
5299 	combobox = gtk_combo_box_new_with_model (model);
5300 	g_object_unref (model);
5301 	gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 1);
5302 	renderer = gtk_cell_renderer_text_new ();
5303 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
5304 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "markup", 0, NULL);
5305 
5306 	gtk_widget_show(combobox);
5307 	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), k);
5308 
5309 	return combobox;
5310 }
5311 /********************************************************************************************************/
add_line_types_combo(GtkWidget * hbox)5312 static GtkWidget *add_line_types_combo(GtkWidget *hbox)
5313 {
5314         GtkTreeIter iter;
5315         GtkTreeStore *store;
5316 	GtkTreeModel *model;
5317 	GtkWidget *combobox;
5318 	GtkCellRenderer *renderer;
5319 
5320 	store = gtk_tree_store_new (1,G_TYPE_STRING);
5321 
5322         gtk_tree_store_append (store, &iter, NULL);
5323         gtk_tree_store_set (store, &iter, 0, "Solid", -1);
5324         gtk_tree_store_append (store, &iter, NULL);
5325         gtk_tree_store_set (store, &iter, 0, "On-Off dashed", -1);
5326         gtk_tree_store_append (store, &iter, NULL);
5327         gtk_tree_store_set (store, &iter, 0, "Double dashed", -1);
5328 
5329         model = GTK_TREE_MODEL (store);
5330 	combobox = gtk_combo_box_new_with_model (model);
5331 	g_object_unref (model);
5332 	gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 1);
5333 	renderer = gtk_cell_renderer_text_new ();
5334 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
5335 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL);
5336 
5337 	return combobox;
5338 }
5339 /****************************************************************************************/
evaluate_formula(G_CONST_RETURN gchar * t)5340 static gdouble evaluate_formula(G_CONST_RETURN gchar* t)
5341 {
5342 	gdouble a = 1.0;
5343 	gchar* pos = strstr(t,"/");
5344 	if(pos && pos[1]!='\0') a = atof(t)/atof(pos+1);
5345 	else
5346 	{
5347 		pos = strstr(t,"*");
5348 		if(pos && pos[1]!='\0') a = atof(t)*atof(pos+1);
5349 		else a = atof(t);
5350 	}
5351 	return a;
5352 }
5353 /****************************************************************************************/
activate_entry_scale_z(GtkEntry * entry,gpointer user_data)5354 static void activate_entry_scale_z(GtkEntry *entry, gpointer user_data)
5355 {
5356 	if(user_data && G_IS_OBJECT(user_data))
5357 	{
5358 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5359 		ContoursPlotData* data = g_object_get_data(G_OBJECT (entry), "CurentData");
5360 		gint loop;
5361 		gdouble a;
5362 		G_CONST_RETURN gchar* t;
5363 
5364   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5365 
5366 		t= gtk_entry_get_text(GTK_ENTRY(entry));
5367 		if(!t) return;
5368 		a = evaluate_formula(t);
5369 		if(data)
5370 		{
5371 			for(loop=0;loop<data->xsize*data->ysize; loop++) data->zValues[loop] *= a;
5372 			for(loop=0;loop<data->nContours; loop++)
5373 			{
5374 				double b = data->contours[loop].value *a;
5375 				free_one_contour(&data->contours[loop]);
5376 				data->contours[loop] = get_contour_point(contoursplot, data, b);
5377 			}
5378 		}
5379 		else
5380 		{
5381 			GList *current_node;
5382 			current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
5383 			for (; current_node!=NULL; current_node=current_node->next)
5384 			{
5385 				data=(ContoursPlotData*)current_node->data;
5386 				for(loop=0;loop<data->xsize*data->ysize; loop++) data->zValues[loop] *= a;
5387 				for(loop=0;loop<data->nContours; loop++)
5388 				{
5389 					double b = data->contours[loop].value*a;
5390 					free_one_contour(&data->contours[loop]);
5391 					data->contours[loop] = get_contour_point(contoursplot, data, b);
5392 				}
5393 			}
5394 		}
5395 		gtk_entry_set_text(GTK_ENTRY(entry),"1.0");
5396 		gtk_editable_set_position(GTK_EDITABLE(entry),3);
5397 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5398 	}
5399 }
5400 /****************************************************************************************/
activate_entry_scale_x(GtkEntry * entry,gpointer user_data)5401 static void activate_entry_scale_x(GtkEntry *entry, gpointer user_data)
5402 {
5403 	if(user_data && G_IS_OBJECT(user_data))
5404 	{
5405 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5406 		ContoursPlotData* data = g_object_get_data(G_OBJECT (entry), "CurentData");
5407 		gint loop,i;
5408 		gdouble a;
5409 		G_CONST_RETURN gchar* t;
5410 
5411   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5412 
5413 		t= gtk_entry_get_text(GTK_ENTRY(entry));
5414 		if(!t) return;
5415 		a = evaluate_formula(t);
5416 		if(data)
5417 		{
5418 			data->xmin *= a;
5419 			data->xmax *= a;
5420 			for(loop=0;loop<data->nContours; loop++)
5421 				for(i=0;i<data->contours[loop].size; i++) data->contours[loop].x[i] *= a;
5422 		}
5423 		else
5424 		{
5425 			GList *current_node;
5426 			current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
5427 			for (; current_node!=NULL; current_node=current_node->next)
5428 			{
5429 				data=(ContoursPlotData*)current_node->data;
5430 				data->xmin *= a;
5431 				data->xmax *= a;
5432 				for(loop=0;loop<data->nContours; loop++)
5433 					for(i=0;i<data->contours[loop].size; i++) data->contours[loop].x[i] *= a;
5434 			}
5435 		}
5436 		gtk_entry_set_text(GTK_ENTRY(entry),"1.0");
5437 		gtk_editable_set_position(GTK_EDITABLE(entry),3);
5438 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5439 	}
5440 }
5441 /****************************************************************************************/
activate_entry_scale_y(GtkEntry * entry,gpointer user_data)5442 static void activate_entry_scale_y(GtkEntry *entry, gpointer user_data)
5443 {
5444 	if(user_data && G_IS_OBJECT(user_data))
5445 	{
5446 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5447 		ContoursPlotData* data = g_object_get_data(G_OBJECT (entry), "CurentData");
5448 		gdouble a;
5449 		gint loop,i;
5450 		G_CONST_RETURN gchar* t;
5451   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5452 		t= gtk_entry_get_text(GTK_ENTRY(entry));
5453 		if(!t) return;
5454 		a = evaluate_formula(t);
5455 		if(data)
5456 		{
5457 			data->ymin *= a;
5458 			data->ymax *= a;
5459 			for(loop=0;loop<data->nContours; loop++)
5460 				for(i=0;i<data->contours[loop].size; i++) data->contours[loop].y[i] *= a;
5461 		}
5462 		else
5463 		{
5464 			GList *current_node;
5465 			current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
5466 			for (; current_node!=NULL; current_node=current_node->next)
5467 			{
5468 				data=(ContoursPlotData*)current_node->data;
5469 				data->ymin *= a;
5470 				data->ymax *= a;
5471 				for(loop=0;loop<data->nContours; loop++)
5472 					for(i=0;i<data->contours[loop].size; i++) data->contours[loop].y[i] *= a;
5473 			}
5474 		}
5475 		gtk_entry_set_text(GTK_ENTRY(entry),"1.0");
5476 		gtk_editable_set_position(GTK_EDITABLE(entry),3);
5477 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5478 	}
5479 }
5480 /****************************************************************************************/
activate_entry_shift_z(GtkEntry * entry,gpointer user_data)5481 static void activate_entry_shift_z(GtkEntry *entry, gpointer user_data)
5482 {
5483 	if(user_data && G_IS_OBJECT(user_data))
5484 	{
5485 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5486 		ContoursPlotData* data = g_object_get_data(G_OBJECT (entry), "CurentData");
5487 		gint loop;
5488 		gdouble a;
5489 		G_CONST_RETURN gchar* t;
5490   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5491 		t= gtk_entry_get_text(GTK_ENTRY(entry));
5492 		if(!t) return;
5493 		a = evaluate_formula(t);
5494 		if(data)
5495 		{
5496 			for(loop=0;loop<data->xsize*data->ysize; loop++) data->zValues[loop] += a;
5497 			for(loop=0;loop<data->nContours; loop++)
5498 			{
5499 				double b = data->contours[loop].value+a;
5500 				free_one_contour(&data->contours[loop]);
5501 				data->contours[loop] = get_contour_point(contoursplot, data, b);
5502 			}
5503 		}
5504 		else
5505 		{
5506 			GList *current_node;
5507 			current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
5508 			for (; current_node!=NULL; current_node=current_node->next)
5509 			{
5510 				data=(ContoursPlotData*)current_node->data;
5511 				for(loop=0;loop<data->xsize*data->ysize; loop++) data->zValues[loop] += a;
5512 				for(loop=0;loop<data->nContours; loop++)
5513 				{
5514 					double b = data->contours[loop].value+a;
5515 					free_one_contour(&data->contours[loop]);
5516 					data->contours[loop] = get_contour_point(contoursplot, data, b);
5517 				}
5518 			}
5519 		}
5520 		gtk_entry_set_text(GTK_ENTRY(entry),"0.0");
5521 		gtk_editable_set_position(GTK_EDITABLE(entry),3);
5522 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5523 	}
5524 }
5525 /****************************************************************************************/
activate_entry_shift_x(GtkEntry * entry,gpointer user_data)5526 static void activate_entry_shift_x(GtkEntry *entry, gpointer user_data)
5527 {
5528 	if(user_data && G_IS_OBJECT(user_data))
5529 	{
5530 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5531 		ContoursPlotData* data = g_object_get_data(G_OBJECT (entry), "CurentData");
5532 		gdouble a;
5533 		gint i,loop;
5534 		G_CONST_RETURN gchar* t;
5535   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5536 		t= gtk_entry_get_text(GTK_ENTRY(entry));
5537 		if(!t) return;
5538 		a = evaluate_formula(t);
5539 		if(data)
5540 		{
5541 			data->xmin += a;
5542 			data->xmax += a;
5543 			for(loop=0;loop<data->nContours; loop++)
5544 				for(i=0;i<data->contours[loop].size; i++) data->contours[loop].x[i] += a;
5545 		}
5546 		else
5547 		{
5548 			GList *current_node;
5549 			current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
5550 			for (; current_node!=NULL; current_node=current_node->next)
5551 			{
5552 				data=(ContoursPlotData*)current_node->data;
5553 				data->xmin += a;
5554 				data->xmax += a;
5555 				for(loop=0;loop<data->nContours; loop++)
5556 					for(i=0;i<data->contours[loop].size; i++) data->contours[loop].x[i] += a;
5557 			}
5558 		}
5559 		gtk_entry_set_text(GTK_ENTRY(entry),"0.0");
5560 		gtk_editable_set_position(GTK_EDITABLE(entry),3);
5561 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5562 	}
5563 }
5564 /****************************************************************************************/
activate_entry_shift_y(GtkEntry * entry,gpointer user_data)5565 static void activate_entry_shift_y(GtkEntry *entry, gpointer user_data)
5566 {
5567 	if(user_data && G_IS_OBJECT(user_data))
5568 	{
5569 		GtkWidget* contoursplot = GTK_WIDGET(user_data);
5570 		ContoursPlotData* data = g_object_get_data(G_OBJECT (entry), "CurentData");
5571 		gdouble a;
5572 		gint i,loop;
5573 		G_CONST_RETURN gchar* t;
5574   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
5575 		t= gtk_entry_get_text(GTK_ENTRY(entry));
5576 		if(!t) return;
5577 		a = evaluate_formula(t);
5578 		if(data)
5579 		{
5580 			data->ymin += a;
5581 			data->ymax += a;
5582 			for(loop=0;loop<data->nContours; loop++)
5583 				for(i=0;i<data->contours[loop].size; i++) data->contours[loop].y[i] += a;
5584 		}
5585 		else
5586 		{
5587 			GList *current_node;
5588 			current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
5589 			for (; current_node!=NULL; current_node=current_node->next)
5590 			{
5591 				data=(ContoursPlotData*)current_node->data;
5592 				data->ymin += a;
5593 				data->ymax += a;
5594 				for(loop=0;loop<data->nContours; loop++)
5595 					for(i=0;i<data->contours[loop].size; i++) data->contours[loop].y[i] += a;
5596 			}
5597 		}
5598 		gtk_entry_set_text(GTK_ENTRY(entry),"0.0");
5599 		gtk_editable_set_position(GTK_EDITABLE(entry),3);
5600 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
5601 	}
5602 }
5603 /****************************************************************************************/
add_contour_data_dialog(GtkWidget * window,GtkWidget * vbox_window,GabeditContoursPlot * contoursplot,ContoursPlotData * data,ContourData * contour)5604 static void add_contour_data_dialog(GtkWidget* window, GtkWidget* vbox_window,
5605 		GabeditContoursPlot* contoursplot, ContoursPlotData* data, ContourData* contour)
5606 {
5607 	gint i,j;
5608 	GtkWidget* frame = NULL;
5609 	GtkWidget* hbox = NULL;
5610 	GtkWidget* vbox_frame = NULL;
5611 	GtkWidget* table = NULL;
5612 	GtkWidget* hbox1 = NULL;
5613 	GtkWidget* label = NULL;
5614 	GtkWidget* combo = NULL;
5615 	GtkWidget* combo_point = NULL;
5616 	GtkWidget* spin = NULL;
5617 	GtkWidget* button = NULL;
5618 	GtkWidget* spin_point = NULL;
5619 	GtkWidget* button_point = NULL;
5620 	GtkWidget* entry_label_contour_str = NULL;
5621 	GtkWidget* entry_label_contour_x = NULL;
5622 	GtkWidget* entry_label_contour_y = NULL;
5623 	gchar t[100];
5624 
5625 	if(!contour) return;
5626 	hbox1=gtk_hbox_new(FALSE, 0);
5627 	gtk_box_pack_start(GTK_BOX(vbox_window), hbox1, TRUE, FALSE, 2);
5628 	gtk_widget_show(hbox1);
5629 
5630 	frame = gtk_frame_new(_("Set line type"));
5631 	gtk_box_pack_start(GTK_BOX(hbox1), frame, TRUE, FALSE, 2);
5632 	gtk_widget_show(frame);
5633 
5634 	hbox=gtk_hbox_new(FALSE, 0);
5635 	gtk_container_add(GTK_CONTAINER(frame), hbox);
5636 	gtk_widget_show(hbox);
5637 
5638 	label=gtk_label_new(_("Line width :"));
5639 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
5640 	gtk_widget_show(label);
5641 
5642 	spin = gtk_spin_button_new_with_range(0, 10, 1);
5643 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), contour->line_width);
5644 	gtk_box_pack_start(GTK_BOX(hbox), spin, TRUE, FALSE, 2);
5645 	gtk_widget_show(spin);
5646 	g_object_set_data(G_OBJECT (window), "SpinLineWidth", spin);
5647 
5648 	label=gtk_label_new(_("Line type :"));
5649 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
5650 	gtk_widget_show(label);
5651 
5652 	combo = add_line_types_combo(hbox);
5653 	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
5654 	if(contour->line_style == GDK_LINE_SOLID) gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
5655 	else if(contour->line_style == GDK_LINE_ON_OFF_DASH) gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
5656 	else if(contour->line_style == GDK_LINE_DOUBLE_DASH) gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 2);
5657 	gtk_widget_show(combo);
5658 	g_object_set_data(G_OBJECT (window), "ComboLineType", combo);
5659 
5660 	label=gtk_label_new(_("Line color :"));
5661 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
5662 	gtk_widget_show(label);
5663 
5664 	button = gtk_color_button_new_with_color (&contour->line_color);
5665 	gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 2);
5666 	gtk_widget_show(button);
5667 	g_object_set_data(G_OBJECT (window), "ColorButton", button);
5668 
5669 	frame = gtk_frame_new(_("Set point type"));
5670 	gtk_box_pack_start(GTK_BOX(vbox_window), frame, TRUE, FALSE, 2);
5671 	gtk_widget_show(frame);
5672 
5673 	hbox=gtk_hbox_new(FALSE, 0);
5674 	gtk_container_add(GTK_CONTAINER(frame), hbox);
5675 	gtk_widget_show(hbox);
5676 
5677 	label=gtk_label_new(_("Point size :"));
5678 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
5679 	gtk_widget_show(label);
5680 
5681 	spin_point = gtk_spin_button_new_with_range(0, 30, 1);
5682 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_point), contour->point_size);
5683 	gtk_box_pack_start(GTK_BOX(hbox), spin_point, TRUE, FALSE, 2);
5684 	gtk_widget_show(spin_point);
5685 	g_object_set_data(G_OBJECT (window), "SpinPointWidth", spin_point);
5686 
5687 	label=gtk_label_new(_("Point type :"));
5688 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
5689 	gtk_widget_show(label);
5690 
5691 	combo_point = add_point_types_combo(hbox, contour);
5692 	gtk_widget_show(combo_point);
5693 	g_object_set_data(G_OBJECT (window), "ComboPointType", combo_point);
5694 
5695 	label=gtk_label_new(_("Point color :"));
5696 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
5697 	gtk_widget_show(label);
5698 
5699 	button_point = gtk_color_button_new_with_color (&contour->point_color);
5700 	gtk_box_pack_start(GTK_BOX(hbox), button_point, TRUE, FALSE, 2);
5701 	gtk_widget_show(button_point);
5702 	g_object_set_data(G_OBJECT (window), "ColorButton", button_point);
5703 
5704 	frame = gtk_frame_new(_("Set label"));
5705 	gtk_box_pack_start(GTK_BOX(vbox_window), frame, TRUE, FALSE, 2);
5706 	gtk_widget_show(frame);
5707 
5708 	vbox_frame=gtk_vbox_new(FALSE, 0);
5709 	gtk_container_add(GTK_CONTAINER(frame), vbox_frame);
5710 	gtk_widget_show(vbox_frame);
5711 
5712 	table = gtk_table_new(3,3,FALSE);
5713 	gtk_container_add(GTK_CONTAINER(vbox_frame),table);
5714 
5715 	i = 0;
5716 	j = 0;
5717 	add_label_at_table(table,_(" Label "),i,j,GTK_JUSTIFY_LEFT);
5718 	j++;
5719 	add_label_at_table(table," : ",i,j,GTK_JUSTIFY_LEFT);
5720 	j++;
5721 	entry_label_contour_str = gtk_entry_new ();
5722 	add_widget_table(table,entry_label_contour_str,i,j);
5723 	if(contour->label) sprintf(t,"%s",contour->label);
5724 	else t[0] = '\0';
5725 	gtk_entry_set_text(GTK_ENTRY(entry_label_contour_str),t);
5726 
5727 	i = 1;
5728 	j = 0;
5729 	add_label_at_table(table,_(" X label "),i,j,GTK_JUSTIFY_LEFT);
5730 	j++;
5731 	add_label_at_table(table," : ",i,j,GTK_JUSTIFY_LEFT);
5732 	j++;
5733 	entry_label_contour_x = gtk_entry_new ();
5734 	add_widget_table(table,entry_label_contour_x,i,j);
5735 	sprintf(t,"%0.10lf",contour->xlabel);
5736 	gtk_entry_set_text(GTK_ENTRY(entry_label_contour_x),t);
5737 
5738 	i = 2;
5739 	j = 0;
5740 	add_label_at_table(table,_(" X label "),i,j,GTK_JUSTIFY_LEFT);
5741 	j++;
5742 	add_label_at_table(table," : ",i,j,GTK_JUSTIFY_LEFT);
5743 	j++;
5744 	entry_label_contour_y = gtk_entry_new ();
5745 	add_widget_table(table,entry_label_contour_y,i,j);
5746 	sprintf(t,"%0.10lf",contour->ylabel);
5747 	gtk_entry_set_text(GTK_ENTRY(entry_label_contour_y),t);
5748 	gtk_widget_show_all(table);
5749 
5750 	gtk_widget_show(window);
5751 
5752 	g_object_set_data(G_OBJECT (spin), "CurentData", data);
5753 	g_object_set_data(G_OBJECT (spin), "CurentContour", contour);
5754 	g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(spin_line_width_changed_value), contoursplot);
5755 	g_object_set_data(G_OBJECT (button), "CurentData", data);
5756 	g_object_set_data(G_OBJECT (button), "CurentContour", contour);
5757 	g_signal_connect(G_OBJECT(button), "color-set", G_CALLBACK(spin_line_color_changed_value), contoursplot);
5758 	g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(combo_line_style_changed_value), contoursplot);
5759 	g_object_set_data(G_OBJECT (combo), "CurentData", data);
5760 	g_object_set_data(G_OBJECT (combo), "CurentContour", contour);
5761 
5762 	g_signal_connect(G_OBJECT(combo_point), "changed", G_CALLBACK(combo_point_style_changed_value), contoursplot);
5763 	g_object_set_data(G_OBJECT (combo_point), "CurentData", data);
5764 	g_object_set_data(G_OBJECT (combo_point), "CurentContour", contour);
5765 
5766 	g_object_set_data(G_OBJECT (spin_point), "CurentData", data);
5767 	g_object_set_data(G_OBJECT (spin_point), "CurentContour", contour);
5768 	g_signal_connect(G_OBJECT(spin_point), "value-changed", G_CALLBACK(spin_point_size_changed_value), contoursplot);
5769 	g_object_set_data(G_OBJECT (button_point), "CurentData", data);
5770 	g_object_set_data(G_OBJECT (button_point), "CurentContour", contour);
5771 	g_signal_connect(G_OBJECT(button_point), "color-set", G_CALLBACK(spin_point_color_changed_value), contoursplot);
5772 
5773 	g_object_set_data(G_OBJECT (entry_label_contour_str), "CurentData", data);
5774 	g_object_set_data(G_OBJECT (entry_label_contour_str), "CurentContour", contour);
5775 	g_object_set_data(G_OBJECT (entry_label_contour_x), "CurentData", data);
5776 	g_object_set_data(G_OBJECT (entry_label_contour_x), "CurentContour", contour);
5777 	g_object_set_data(G_OBJECT (entry_label_contour_y), "CurentData", data);
5778 	g_object_set_data(G_OBJECT (entry_label_contour_y), "CurentContour", contour);
5779 	g_signal_connect (G_OBJECT (entry_label_contour_str), "activate", (GCallback)activate_entry_label_contour_str, contoursplot);
5780 	g_signal_connect (G_OBJECT (entry_label_contour_x), "activate", (GCallback)activate_entry_label_contour_x, contoursplot);
5781 	g_signal_connect (G_OBJECT (entry_label_contour_y), "activate", (GCallback)activate_entry_label_contour_y, contoursplot);
5782 }
5783 /****************************************************************************************/
set_data_dialog(GabeditContoursPlot * contoursplot,ContoursPlotData * data,ContourData * contour)5784 static void set_data_dialog(GabeditContoursPlot* contoursplot, ContoursPlotData* data,ContourData* contour)
5785 {
5786 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
5787 	GtkWidget* frame = NULL;
5788 	GtkWidget* hbox = NULL;
5789 	GtkWidget* vbox = NULL;
5790 	GtkWidget* label = NULL;
5791 	GtkWidget* buttonSave = NULL;
5792 	GtkWidget* buttonRemove = NULL;
5793 	GtkWidget* buttonAutoRanges = NULL;
5794 	GtkWidget* buttonAutoRangesAll = NULL;
5795 	GtkWidget* parentWindow = NULL;
5796 	GtkWidget* vbox_window = NULL;
5797 	GtkWidget* entry_scale_x = NULL;
5798 	GtkWidget* entry_scale_y = NULL;
5799 	GtkWidget* entry_scale_z = NULL;
5800 	GtkWidget* entry_shift_x = NULL;
5801 	GtkWidget* entry_shift_y = NULL;
5802 	GtkWidget* entry_shift_z = NULL;
5803 
5804 	gtk_window_set_title (GTK_WINDOW (window), _("Set data options"));
5805 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
5806 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
5807 
5808 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(destroy_data_dialog), (gpointer)contoursplot);
5809 
5810 	vbox_window=gtk_vbox_new(FALSE, 0);
5811 	gtk_container_add(GTK_CONTAINER(window), vbox_window);
5812 	gtk_widget_show(vbox_window);
5813 
5814 	add_contour_data_dialog(window, vbox_window, contoursplot, data, contour);
5815 
5816 	frame = gtk_frame_new(NULL);
5817 	gtk_box_pack_start(GTK_BOX(vbox_window), frame, TRUE, FALSE, 2);
5818 	gtk_widget_show(frame);
5819 
5820 	vbox=gtk_vbox_new(FALSE, 0);
5821 	gtk_container_add(GTK_CONTAINER(frame), vbox);
5822 	gtk_widget_show(vbox);
5823 
5824 	hbox=gtk_hbox_new(FALSE, 0);
5825 	gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 2);
5826 	gtk_widget_show(hbox);
5827 
5828 	label=gtk_label_new(_("Scale X : "));
5829 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5830 	gtk_widget_show(label);
5831 
5832 	entry_scale_x = gtk_entry_new();
5833 	gtk_widget_set_size_request(entry_scale_x,50,-1);
5834 	gtk_entry_set_text(GTK_ENTRY(entry_scale_x),"1.0");
5835 	gtk_box_pack_start(GTK_BOX(hbox), entry_scale_x, FALSE, FALSE, 2);
5836 	gtk_widget_show(entry_scale_x);
5837 
5838 	label=gtk_label_new(_("Scale Y : "));
5839 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5840 	gtk_widget_show(label);
5841 
5842 	entry_scale_y = gtk_entry_new();
5843 	gtk_widget_set_size_request(entry_scale_y,50,-1);
5844 	gtk_entry_set_text(GTK_ENTRY(entry_scale_y),"1.0");
5845 	gtk_box_pack_start(GTK_BOX(hbox), entry_scale_y, FALSE, FALSE, 2);
5846 	gtk_widget_show(entry_scale_y);
5847 
5848 	label=gtk_label_new(_("Scale Z : "));
5849 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5850 	gtk_widget_show(label);
5851 
5852 	entry_scale_z = gtk_entry_new();
5853 	gtk_widget_set_size_request(entry_scale_z,50,-1);
5854 	gtk_entry_set_text(GTK_ENTRY(entry_scale_z),"1.0");
5855 	gtk_box_pack_start(GTK_BOX(hbox), entry_scale_z, FALSE, FALSE, 2);
5856 	gtk_widget_show(entry_scale_z);
5857 
5858 	hbox=gtk_hbox_new(FALSE, 0);
5859 	gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 2);
5860 	gtk_widget_show(hbox);
5861 
5862 	label=gtk_label_new(_("Shift  X : "));
5863 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5864 	gtk_widget_show(label);
5865 
5866 	entry_shift_x = gtk_entry_new();
5867 	gtk_widget_set_size_request(entry_shift_x,50,-1);
5868 	gtk_entry_set_text(GTK_ENTRY(entry_shift_x),"0.0");
5869 	gtk_box_pack_start(GTK_BOX(hbox), entry_shift_x, FALSE, FALSE, 2);
5870 	gtk_widget_show(entry_shift_x);
5871 
5872 	label=gtk_label_new(_("Shift  Y : "));
5873 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5874 	gtk_widget_show(label);
5875 
5876 
5877 	entry_shift_y = gtk_entry_new();
5878 	gtk_widget_set_size_request(entry_shift_y,50,-1);
5879 	gtk_entry_set_text(GTK_ENTRY(entry_shift_y),"0.0");
5880 	gtk_box_pack_start(GTK_BOX(hbox), entry_shift_y, FALSE, FALSE, 2);
5881 	gtk_widget_show(entry_shift_y);
5882 
5883 	label=gtk_label_new(_("Shift  Z : "));
5884 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5885 	gtk_widget_show(label);
5886 
5887 	entry_shift_z = gtk_entry_new();
5888 	gtk_widget_set_size_request(entry_shift_z,50,-1);
5889 	gtk_entry_set_text(GTK_ENTRY(entry_shift_z),"0.0");
5890 	gtk_box_pack_start(GTK_BOX(hbox), entry_shift_z, FALSE, FALSE, 2);
5891 	gtk_widget_show(entry_shift_z);
5892 
5893 	frame = gtk_frame_new(NULL);
5894 	gtk_box_pack_start(GTK_BOX(vbox_window), frame, TRUE, FALSE, 2);
5895 	gtk_widget_show(frame);
5896 
5897 	hbox=gtk_hbox_new(FALSE, 0);
5898 	gtk_container_add(GTK_CONTAINER(frame), hbox);
5899 	gtk_widget_show(hbox);
5900 
5901 	buttonAutoRanges = gtk_button_new_with_label (_("Auto ranges"));
5902 	gtk_box_pack_start(GTK_BOX(hbox), buttonAutoRanges, TRUE, TRUE, 4);
5903 	gtk_widget_show (buttonAutoRanges);
5904 
5905 	buttonAutoRangesAll = gtk_button_new_with_label (_("Auto ranges all"));
5906 	gtk_box_pack_start(GTK_BOX(hbox), buttonAutoRangesAll, TRUE, TRUE, 4);
5907 	gtk_widget_show (buttonAutoRangesAll);
5908 
5909 
5910 	buttonSave = gtk_button_new_with_label (_("Save"));
5911 	gtk_box_pack_start(GTK_BOX(hbox), buttonSave, TRUE, TRUE, 4);
5912 	gtk_widget_show (buttonSave);
5913 
5914 	buttonRemove = gtk_button_new_with_label (_("Remove"));
5915 	gtk_box_pack_start(GTK_BOX(hbox), buttonRemove, TRUE, TRUE, 4);
5916 	gtk_widget_show (buttonRemove);
5917 
5918 
5919 
5920 	g_object_set_data(G_OBJECT (buttonSave), "CurentData", data);
5921 	g_signal_connect(G_OBJECT(buttonSave), "clicked", G_CALLBACK(save_data_dlg), contoursplot);
5922 
5923 	g_object_set_data(G_OBJECT (buttonRemove), "CurentData", data);
5924 	g_object_set_data(G_OBJECT (buttonRemove), "Window", window);
5925 	g_object_set_data(G_OBJECT (buttonRemove), "ContoursPLOT", contoursplot);
5926 	g_signal_connect(G_OBJECT(buttonRemove), "clicked", G_CALLBACK(remove_data_dlg), contoursplot);
5927 
5928 	g_object_set_data(G_OBJECT (buttonAutoRanges), "CurentData", data);
5929 	g_signal_connect(G_OBJECT(buttonAutoRanges), "clicked", G_CALLBACK(auto_range_activate), contoursplot);
5930 
5931 	g_object_set_data(G_OBJECT (buttonAutoRangesAll), "CurentData", NULL);
5932 	g_signal_connect(G_OBJECT(buttonAutoRangesAll), "clicked", G_CALLBACK(auto_range_activate), contoursplot);
5933 
5934 	g_object_set_data(G_OBJECT (entry_scale_x), "CurentData", data);
5935 	g_object_set_data(G_OBJECT (entry_scale_y), "CurentData", data);
5936 	g_object_set_data(G_OBJECT (entry_shift_x), "CurentData", data);
5937 	g_object_set_data(G_OBJECT (entry_shift_y), "CurentData", data);
5938 	g_signal_connect (G_OBJECT (entry_scale_x), "activate", (GCallback)activate_entry_scale_x, contoursplot);
5939 	g_signal_connect (G_OBJECT (entry_scale_y), "activate", (GCallback)activate_entry_scale_y, contoursplot);
5940 	g_signal_connect (G_OBJECT (entry_scale_z), "activate", (GCallback)activate_entry_scale_z, contoursplot);
5941 	g_signal_connect (G_OBJECT (entry_shift_x), "activate", (GCallback)activate_entry_shift_x, contoursplot);
5942 	g_signal_connect (G_OBJECT (entry_shift_y), "activate", (GCallback)activate_entry_shift_y, contoursplot);
5943 	g_signal_connect (G_OBJECT (entry_shift_z), "activate", (GCallback)activate_entry_shift_z, contoursplot);
5944 
5945 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
5946 	if(parentWindow)
5947 	{
5948 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
5949 	}
5950 	gtk_widget_show(window);
5951 	/* list_utf8();*/
5952 
5953 
5954 }
5955 /*********************************************************************************************************************/
applyColorMapOptions(GtkWidget * dialogWindow,gpointer data)5956 static void applyColorMapOptions(GtkWidget *dialogWindow, gpointer data)
5957 {
5958 	GtkWidget* buttonMultiColor;
5959 	GtkWidget* button2Colors;
5960 	GtkWidget* buttonUniColor;
5961 	GtkWidget* selectorUniColor;
5962 	GtkWidget* selector2Colors1;
5963 	GtkWidget* selector2Colors2;
5964 	GabeditContoursPlot* contoursplot;
5965 	GtkWidget* entryMin;
5966 	GtkWidget* entryMax;
5967 	GtkWidget* entryNLabels;
5968 	gdouble min = -1;
5969 	gdouble max = 1;
5970 	gint N = 0;
5971 	G_CONST_RETURN gchar *temp = NULL;
5972 
5973 	if(!GTK_IS_WIDGET(dialogWindow)) return;
5974 	buttonMultiColor = g_object_get_data(G_OBJECT (dialogWindow), "ButtonMultiColor");
5975 	button2Colors = g_object_get_data(G_OBJECT (dialogWindow), "Button2Colors");
5976 	buttonUniColor = g_object_get_data(G_OBJECT (dialogWindow), "ButtonUniColor");
5977 	selectorUniColor = g_object_get_data(G_OBJECT (dialogWindow), "SelectorUniColor");
5978 	selector2Colors1 = g_object_get_data(G_OBJECT (dialogWindow), "Selector2Colors1");
5979 	selector2Colors2 = g_object_get_data(G_OBJECT (dialogWindow), "Selector2Colors2");
5980 	entryMin =(GtkWidget*)g_object_get_data(G_OBJECT (dialogWindow), "EntryMin");
5981 	entryMax =(GtkWidget*)g_object_get_data(G_OBJECT (dialogWindow), "EntryMax");
5982 	entryNLabels =(GtkWidget*)g_object_get_data(G_OBJECT (dialogWindow), "EntryNLabels");
5983 	contoursplot = (GabeditContoursPlot* )g_object_get_data(G_OBJECT (dialogWindow), "ContoursPlot");
5984 	if(!entryNLabels) return;
5985         temp	= gtk_entry_get_text(GTK_ENTRY(entryNLabels));
5986 	N = atoi(temp);
5987 	if(N<=0)
5988 	{
5989 		Message(_("Error : The number of labels should be a positive integer. "),_("Error"));
5990 		return;
5991 	}
5992         if(!get_a_float(entryMin,&min,_("Error : The minimal value should be float."))) return;
5993         if(!get_a_float(entryMax,&max,_("Error : The maximal value should be float."))) return;
5994 	if( max<=min)
5995 	{
5996 		Message(_("Error :  The minimal value should be smaller than the maximal value "),_("Error"));
5997 		return;
5998 	}
5999 
6000 	if(!buttonMultiColor) return;
6001 	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(buttonMultiColor)))
6002 	{
6003 
6004   		contoursplot->colorsMap.type=1;
6005 	}
6006 	else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button2Colors)) && selector2Colors1 && selector2Colors2)
6007 	{
6008 		GdkColor color;
6009   		contoursplot->colorsMap.type=2;
6010 		gtk_color_button_get_color (GTK_COLOR_BUTTON(selector2Colors1), &color);
6011 		contoursplot->colorsMap.colors[0][0] = color.red/65535.0;
6012 		contoursplot->colorsMap.colors[0][1] = color.green/65535.0;
6013 		contoursplot->colorsMap.colors[0][2] = color.blue/65535.0;
6014 		gtk_color_button_get_color (GTK_COLOR_BUTTON(selector2Colors2), &color);
6015 		contoursplot->colorsMap.colors[1][0] = color.red/65535.0;
6016 		contoursplot->colorsMap.colors[1][1] = color.green/65535.0;
6017 		contoursplot->colorsMap.colors[1][2] = color.blue/65535.0;
6018 
6019 	}
6020 	else if(selectorUniColor)
6021 	{
6022 		GdkColor color;
6023   		contoursplot->colorsMap.type=3;
6024 		gtk_color_button_get_color (GTK_COLOR_BUTTON(selectorUniColor), &color);
6025 		contoursplot->colorsMap.colors[2][0] = color.red/65535.0;
6026 		contoursplot->colorsMap.colors[2][1] = color.green/65535.0;
6027 		contoursplot->colorsMap.colors[2][2] = color.blue/65535.0;
6028 	}
6029   	contoursplot->colormap_nlegends = N;
6030 	reset_color_map_min_max(GTK_WIDGET(contoursplot), min, max);
6031 	reset_contour_colors(GTK_WIDGET(contoursplot), NULL);
6032 }
6033 /*********************************************************************************************************************/
addRadioButtonColorMapToATable(GtkWidget * table,GtkWidget * friendButton,gchar * label,gint i,gint j,gint k)6034 static GtkWidget* addRadioButtonColorMapToATable(GtkWidget* table, GtkWidget* friendButton, gchar* label, gint i, gint j, gint k)
6035 {
6036 	GtkWidget *newButton;
6037 
6038 	if(friendButton)
6039 		newButton = gtk_radio_button_new_with_label( gtk_radio_button_get_group (GTK_RADIO_BUTTON (friendButton)), label);
6040 	else
6041 		newButton = gtk_radio_button_new_with_label( NULL, label);
6042 
6043 	gtk_table_attach(GTK_TABLE(table),newButton,j,j+k,i,i+1,
6044 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
6045 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
6046                   3,3);
6047 
6048 	g_object_set_data(G_OBJECT (newButton), "Type",NULL);
6049 	return newButton;
6050 }
6051 /*********************************************************************************************************************/
createColorMapOptionsFrame(GtkWidget * dialogWindow,GtkWidget * box)6052 static void createColorMapOptionsFrame(GtkWidget* dialogWindow, GtkWidget *box)
6053 {
6054 	GtkWidget* button;
6055 	GtkWidget* frame;
6056 	GtkWidget* vboxFrame;
6057 	GtkWidget *table = gtk_table_new(3,3,TRUE);
6058 	gint i;
6059 	GtkWidget *selector;
6060 	GdkColor color;
6061 	GabeditContoursPlot* contoursplot = NULL;
6062 
6063 	if(!GTK_IS_WIDGET(dialogWindow)) return;
6064 	contoursplot = (GabeditContoursPlot* )g_object_get_data(G_OBJECT (dialogWindow), "ContoursPlot");
6065 
6066 	color.red = 65535;
6067 	color.green = 65535;
6068 	color.blue = 65535;
6069 	frame = gtk_frame_new (_("Color mapping type"));
6070 	gtk_widget_show (frame);
6071 	gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 3);
6072 	gtk_frame_set_label_align (GTK_FRAME (frame), 0.5, 0.5);
6073 
6074 	vboxFrame = gtk_vbox_new (FALSE, 3);
6075 	gtk_widget_show (vboxFrame);
6076 	gtk_container_add (GTK_CONTAINER (frame), vboxFrame);
6077 
6078 	gtk_box_pack_start (GTK_BOX (vboxFrame), table, TRUE, TRUE, 0);
6079 
6080 	i = 0;
6081 	button =  NULL;
6082 	button = addRadioButtonColorMapToATable(table, button, _("Multi color"), i, 0,1);
6083 	if(contoursplot->colorsMap.type == 1) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
6084 	g_object_set_data(G_OBJECT (dialogWindow), "ButtonMultiColor",button);
6085 
6086 	i = 1;
6087 	button = addRadioButtonColorMapToATable(table, button, _("2 colors"), i, 0,1);
6088 	if(contoursplot->colorsMap.type == 2) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
6089 	g_object_set_data(G_OBJECT (dialogWindow), "Button2Colors",button);
6090 
6091 	color.red = (gushort)(contoursplot->colorsMap.colors[0][0]*65535);
6092 	color.green = (gushort)(contoursplot->colorsMap.colors[0][1]*65535);
6093 	color.blue = (gushort)(contoursplot->colorsMap.colors[0][2]*65535);
6094 	selector = gtk_color_button_new_with_color (&color);
6095 	gtk_table_attach(GTK_TABLE(table),selector,1,2,i,i+1,
6096 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
6097 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
6098                   3,3);
6099 	g_object_set_data(G_OBJECT (dialogWindow), "Selector2Colors1",selector);
6100 
6101 	color.red = (gushort)(contoursplot->colorsMap.colors[1][0]*65535);
6102 	color.green = (gushort)(contoursplot->colorsMap.colors[1][1]*65535);
6103 	color.blue = (gushort)(contoursplot->colorsMap.colors[1][2]*65535);
6104 	selector = gtk_color_button_new_with_color (&color);
6105 	gtk_table_attach(GTK_TABLE(table),selector,2,3,i,i+1,
6106 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
6107 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
6108                   3,3);
6109 	g_object_set_data(G_OBJECT (dialogWindow), "Selector2Colors2",selector);
6110 
6111 	i = 2;
6112 	button = addRadioButtonColorMapToATable(table, button, _("Unicolor"), i, 0,1);
6113 	if(contoursplot->colorsMap.type == 3) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
6114 
6115 	color.red = (gushort)(contoursplot->colorsMap.colors[2][0]*65535);
6116 	color.green = (gushort)(contoursplot->colorsMap.colors[2][1]*65535);
6117 	color.blue = (gushort)(contoursplot->colorsMap.colors[2][2]*65535);
6118 	selector = gtk_color_button_new_with_color (&color);
6119 	gtk_table_attach(GTK_TABLE(table),selector,1,2,i,i+1,
6120 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
6121 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
6122                   3,3);
6123 	g_object_set_data(G_OBJECT (dialogWindow), "SelectorUniColor",selector);
6124 	g_object_set_data(G_OBJECT (dialogWindow), "ButtonUniColor",button);
6125 
6126 }
6127 /****************************************************************************************************/
createColorMapOptionsWindow(GtkWidget * contoursplot)6128 static void createColorMapOptionsWindow(GtkWidget* contoursplot)
6129 {
6130 	GtkWidget *dialogWindow = NULL;
6131 	GtkWidget *button;
6132 	GtkWidget *frame;
6133 	GtkWidget *hbox;
6134 	GtkWidget *vboxframe;
6135 	gchar t[BSIZE];
6136 	gint i,j;
6137 	GtkWidget *table;
6138 	GtkWidget* entryMin;
6139 	GtkWidget* entryMax;
6140 	GtkWidget* entryNLabels;
6141 	gdouble min = -1;
6142 	gdouble max = 1;
6143   	ColorMap* colorMap = NULL;
6144 
6145 	colorMap =GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap;
6146 	if(colorMap && colorMap->numberOfColors>0)
6147 	{
6148     		min = colorMap->colorValue[0].value;
6149     		max = colorMap->colorValue[colorMap->numberOfColors-1].value;
6150 	}
6151 
6152 	dialogWindow = gtk_dialog_new();
6153 	gtk_widget_realize(GTK_WIDGET(dialogWindow));
6154 	sprintf(t, _("Color Mapping options"));
6155 	gtk_window_set_title(GTK_WINDOW(dialogWindow),t);
6156 
6157 	gtk_window_set_modal (GTK_WINDOW (dialogWindow), TRUE);
6158 	gtk_window_set_position(GTK_WINDOW(dialogWindow),GTK_WIN_POS_CENTER);
6159 
6160 	g_signal_connect(G_OBJECT(dialogWindow), "delete_event", (GCallback)gtk_widget_destroy, NULL);
6161 	g_object_set_data(G_OBJECT (dialogWindow), "ContoursPlot",contoursplot);
6162 
6163 	frame = gtk_frame_new (NULL);
6164 	gtk_widget_show (frame);
6165 	gtk_box_pack_start (GTK_BOX (GTK_WIDGET(GTK_DIALOG(dialogWindow)->vbox)), frame, TRUE, TRUE, 3);
6166 
6167 	vboxframe = gtk_vbox_new (FALSE, 1);
6168 	gtk_widget_show (vboxframe);
6169 	gtk_container_add (GTK_CONTAINER (frame), vboxframe);
6170 
6171 	hbox = gtk_hbox_new (FALSE, 1);
6172 	gtk_widget_show (hbox);
6173 	gtk_box_pack_start (GTK_BOX (vboxframe), hbox, TRUE, TRUE, 0);
6174 
6175 	createColorMapOptionsFrame(dialogWindow,hbox);
6176 
6177 	hbox = gtk_hbox_new (FALSE, 1);
6178 	gtk_widget_show (hbox);
6179 	gtk_box_pack_start (GTK_BOX (vboxframe), hbox, TRUE, TRUE, 0);
6180 
6181 	table = gtk_table_new(3,3,FALSE);
6182 	gtk_box_pack_start (GTK_BOX (hbox), table, TRUE, TRUE, 3);
6183 
6184 	i = 0;
6185 	j = 0;
6186 	add_label_at_table(table,_(" Min iso-value "),i,j,GTK_JUSTIFY_LEFT);
6187 	j++;
6188 	add_label_at_table(table," : ",i,j,GTK_JUSTIFY_LEFT);
6189 	j++;
6190 	entryMin = gtk_entry_new ();
6191 	add_widget_table(table,entryMin,i,j);
6192 	sprintf(t,"%f",min);
6193 	gtk_entry_set_text(GTK_ENTRY(entryMin),t);
6194 
6195 	i = 1;
6196 	j = 0;
6197 	add_label_at_table(table,_(" Max iso-value "),i,j,GTK_JUSTIFY_LEFT);
6198 	j++;
6199 	add_label_at_table(table," : ",i,j,GTK_JUSTIFY_LEFT);
6200 	j++;
6201 	entryMax = gtk_entry_new ();
6202 	add_widget_table(table,entryMax,i,j);
6203 	sprintf(t,"%f",max);
6204 	gtk_entry_set_text(GTK_ENTRY(entryMax),t);
6205 
6206 	i = 2;
6207 	j = 0;
6208 	add_label_at_table(table,_(" # of labels "),i,j,GTK_JUSTIFY_LEFT);
6209 	j++;
6210 	add_label_at_table(table," : ",i,j,GTK_JUSTIFY_LEFT);
6211 	j++;
6212 	entryNLabels = gtk_entry_new ();
6213 	add_widget_table(table,entryNLabels,i,j);
6214 	if(GABEDIT_ContoursPLOT(contoursplot)->colormap_nlegends>0)
6215 		sprintf(t,"%d",GABEDIT_ContoursPLOT(contoursplot)->colormap_nlegends);
6216 	else sprintf(t,"20");
6217 	gtk_entry_set_text(GTK_ENTRY(entryNLabels),t);
6218 
6219 	g_object_set_data(G_OBJECT (dialogWindow), "EntryMin",entryMin);
6220 	g_object_set_data(G_OBJECT (dialogWindow), "EntryMax",entryMax);
6221 	g_object_set_data(G_OBJECT (dialogWindow), "EntryNLabels",entryNLabels);
6222 
6223 	gtk_box_set_homogeneous (GTK_BOX( GTK_DIALOG(dialogWindow)->action_area), TRUE);
6224 
6225 	button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
6226 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(dialogWindow)->action_area), button, FALSE, TRUE, 5);
6227 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
6228 	g_signal_connect_swapped(G_OBJECT(button), "clicked", (GCallback)gtk_widget_destroy, GTK_OBJECT(dialogWindow));
6229 
6230 	button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
6231 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(dialogWindow)->action_area), button, FALSE, TRUE, 5);
6232 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
6233 	g_signal_connect_swapped(G_OBJECT(button), "clicked", (GCallback)applyColorMapOptions, GTK_OBJECT(dialogWindow));
6234 
6235 	button = gtk_button_new_from_stock (GTK_STOCK_OK);
6236 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(dialogWindow)->action_area), button, FALSE, TRUE, 5);
6237 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
6238 	gtk_widget_grab_default(button);
6239 	g_signal_connect_swapped(G_OBJECT(button), "clicked", (GCallback)applyColorMapOptions, GTK_OBJECT(dialogWindow));
6240 	g_signal_connect_swapped(G_OBJECT(button), "clicked", (GCallback)gtk_widget_destroy, GTK_OBJECT(dialogWindow));
6241 
6242 
6243 	gtk_widget_show_all(dialogWindow);
6244 }
6245 /****************************************************************************************/
toggle_action(GtkAction * action)6246 static void toggle_action (GtkAction *action)
6247 {
6248 	const gchar *name = gtk_action_get_name (action);
6249 	gboolean enable = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
6250 	GtkWidget* contoursplot = g_object_get_data(G_OBJECT (action), "ContoursPLOT");
6251 	if(!contoursplot) return;
6252 	if(!strcmp(name,"HGridShowMajor"))
6253 		contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMAJOR_GRID, enable);
6254 	else if(!strcmp(name,"HGridShowMinor"))
6255 		contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMINOR_GRID, enable);
6256 	else if(!strcmp(name,"VGridShowMajor"))
6257 		contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMAJOR_GRID, enable);
6258 	else if(!strcmp(name,"VGridShowMinor"))
6259 		contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMINOR_GRID, enable);
6260 	else if(!strcmp(name,"ShowColorMap"))
6261 		contoursplot_show_colormap (GABEDIT_ContoursPLOT(contoursplot), enable);
6262 	else if(!strcmp(name,"ShowLabelContours"))
6263 		contoursplot_show_label_contours (GABEDIT_ContoursPLOT(contoursplot), enable);
6264 	else if(!strcmp(name,"DashedNegativeContours"))
6265 		contoursplot_dashed_negative_contours (GABEDIT_ContoursPLOT(contoursplot), enable);
6266 	else if(!strcmp(name,"LegendShowLeft"))
6267 		contoursplot_show_left_legends (GABEDIT_ContoursPLOT(contoursplot), enable);
6268 	else if(!strcmp(name,"LegendShowRight"))
6269 		contoursplot_show_right_legends (GABEDIT_ContoursPLOT(contoursplot), enable);
6270 	else if(!strcmp(name,"LegendShowTop"))
6271 		contoursplot_show_top_legends (GABEDIT_ContoursPLOT(contoursplot), enable);
6272 	else if(!strcmp(name,"LegendShowBottom"))
6273 		contoursplot_show_bottom_legends (GABEDIT_ContoursPLOT(contoursplot), enable);
6274 	else if(!strcmp(name,"DirectionReflectX"))
6275 		contoursplot_reflect_x (GABEDIT_ContoursPLOT(contoursplot), enable);
6276 	else if(!strcmp(name,"DirectionReflectY"))
6277 		contoursplot_reflect_y (GABEDIT_ContoursPLOT(contoursplot), enable);
6278 }
6279 /*--------------------------------------------------------------------------------------------------------------------*/
6280 static GtkToggleActionEntry gtkActionToggleEntries[] =
6281 {
6282 	{ "HGridShowMajor", NULL, N_("show _H major"), NULL, "show H major", G_CALLBACK (toggle_action), TRUE },
6283 	{ "HGridShowMinor", NULL, N_("show _H minor"), NULL, "show H minor", G_CALLBACK (toggle_action), FALSE },
6284 	{ "VGridShowMajor", NULL, N_("show _V major"), NULL, "show V major", G_CALLBACK (toggle_action), TRUE },
6285 	{ "VGridShowMinor", NULL, N_("show _V minor"), NULL, "show V minor", G_CALLBACK (toggle_action), FALSE },
6286 	{ "LegendShowLeft", NULL, N_("show _left"), NULL, "show left", G_CALLBACK (toggle_action), TRUE },
6287 	{ "LegendShowRight", NULL, N_("show _right"), NULL, "show right", G_CALLBACK (toggle_action), TRUE },
6288 	{ "LegendShowTop", NULL, N_("show _top"), NULL, "show top", G_CALLBACK (toggle_action), TRUE },
6289 	{ "LegendShowBottom", NULL, N_("show _bottom"), NULL, "show bottom", G_CALLBACK (toggle_action), TRUE },
6290 	{ "DirectionReflectX", NULL, N_("_X reflect"), NULL, "X reflect", G_CALLBACK (toggle_action), FALSE },
6291 	{ "DirectionReflectY", NULL, N_("_Y reflect"), NULL, "Y reflect", G_CALLBACK (toggle_action), FALSE },
6292 	{ "ShowColorMap", NULL, N_("show _colormap"), NULL, "show colormap", G_CALLBACK (toggle_action), FALSE },
6293 	{ "ShowLabelContours", NULL, N_("show _label contours"), NULL, "show label contours", G_CALLBACK (toggle_action), FALSE },
6294 	{ "DashedNegativeContours", NULL, N_("dashed negative contours"), NULL, "dashed negative contours", G_CALLBACK (toggle_action), FALSE },
6295 };
6296 /*--------------------------------------------------------------------------------------------------------------------*/
init_toggle_entries(GtkWidget * contoursplot)6297 static void init_toggle_entries (GtkWidget* contoursplot)
6298 {
6299 	contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMAJOR_GRID, gtkActionToggleEntries[0].is_active);
6300 	contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMINOR_GRID, gtkActionToggleEntries[1].is_active);
6301 	contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMAJOR_GRID, gtkActionToggleEntries[2].is_active);
6302 	contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMINOR_GRID, gtkActionToggleEntries[3].is_active);
6303 	contoursplot_show_left_legends (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[4].is_active);
6304 	contoursplot_show_right_legends (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[5].is_active);
6305 	contoursplot_show_top_legends (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[6].is_active);
6306 	contoursplot_show_bottom_legends (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[7].is_active);
6307 
6308 	contoursplot_reflect_x (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[8].is_active);
6309 	contoursplot_reflect_y (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[9].is_active);
6310 	contoursplot_show_colormap (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[10].is_active);
6311 	contoursplot_show_label_contours (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[11].is_active);
6312 	contoursplot_dashed_negative_contours (GABEDIT_ContoursPLOT(contoursplot), gtkActionToggleEntries[12].is_active);
6313 }
6314 static gint numberOfGtkActionToggleEntries = G_N_ELEMENTS (gtkActionToggleEntries);
6315 /*********************************************************************************************************************/
activate_action(GtkAction * action)6316 static void activate_action (GtkAction *action)
6317 {
6318 	const gchar *name = gtk_action_get_name (action);
6319 	GtkWidget* contoursplot = g_object_get_data(G_OBJECT (action), "ContoursPLOT");
6320 	if(!strcmp(name,"SetTicks")) { set_ticks_dialog(contoursplot); }
6321 	if(!strcmp(name,"SetMargins")) { set_margins_dialog(contoursplot); }
6322 	if(!strcmp(name,"SetRanges")) { set_ranges_dialog(contoursplot); }
6323 	if(!strcmp(name,"SetLabels")) { set_labels_dialog(contoursplot); }
6324 	if(!strcmp(name,"SetDigits")) { set_digits_dialog(contoursplot); }
6325 	if(!strcmp(name,"SetFontSize")) { set_font_size_dialog(contoursplot); }
6326 	if(!strcmp(name,"SetAutoRanges")) { gabedit_contoursplot_set_autorange(GABEDIT_ContoursPLOT(contoursplot), NULL); }
6327 	if(!strcmp(name,"DataRead")) { read_data_dlg(contoursplot); }
6328 	if(!strcmp(name,"DataRemoveAll")) { remove_all_data_dlg(contoursplot); }
6329 	if(!strcmp(name,"ContoursSet")) {  create_contours(contoursplot,NULL);}
6330 	if(!strcmp(name,"ContoursDelete")) {  delete_contours(contoursplot,NULL);}
6331 	if(!strcmp(name,"ContoursBuildLabelPositions")) {
6332 		contoursplot_build_position_label_contours(GABEDIT_ContoursPLOT(contoursplot));
6333 	}
6334 	if(!strcmp(name,"ColorMapSet")) { createColorMapOptionsWindow(contoursplot);}
6335 	if(!strcmp(name,"ObjectsInsertText")) { begin_insert_objects_text(contoursplot); }
6336 	if(!strcmp(name,"ObjectsDeleteTexts")) { delete_objects_text(contoursplot); }
6337 	if(!strcmp(name,"ObjectsInsertLine")) { begin_insert_objects_line(contoursplot); }
6338 	if(!strcmp(name,"ObjectsDeleteLines")) { delete_objects_line(contoursplot); }
6339 	if(!strcmp(name,"ObjectsInsertImage")) { begin_insert_objects_image(contoursplot); }
6340 	if(!strcmp(name,"ObjectsInsertImageClip")) { insert_objects_image_from_clipboard(contoursplot); }
6341 	if(!strcmp(name,"ObjectsDeleteImages")) { delete_objects_image(contoursplot); }
6342 	if(!strcmp(name,"ThemesPublication")) { set_theme_publication(contoursplot); }
6343 	if(!strcmp(name,"ThemesGreenBlack")) { set_theme_green_black(contoursplot); }
6344 	if(!strcmp(name,"ThemesOther")) { set_theme_dialog(contoursplot); }
6345 	if(!strcmp(name,"ScreenCaptureBMP")) {  saveImageDlg(contoursplot, "bmp");}
6346 	if(!strcmp(name,"ScreenCaptureJPEG")) {  saveImageDlg(contoursplot, "jpeg");}
6347 	if(!strcmp(name,"ScreenCapturePNG")) {  saveImageDlg(contoursplot, "png");}
6348 	if(!strcmp(name,"ScreenCaptureTPNG")) {  saveImageDlg(contoursplot, "tpng");}
6349 	if(!strcmp(name,"ScreenCaptureTIF")) {  saveImageDlg(contoursplot, "tif");}
6350 	if(!strcmp(name,"ScreenCaptureClipBoard")) {  copyImageToClipBoard(contoursplot); }
6351 	if(!strcmp(name,"ExportSVG")) {  exportImageDlg(contoursplot, "svg");}
6352 	if(!strcmp(name,"ExportPDF")) {  exportImageDlg(contoursplot, "pdf");}
6353 	if(!strcmp(name,"ExportPS")) {  exportImageDlg(contoursplot, "ps");}
6354 	if(!strcmp(name,"ExportEPS")) {  exportImageDlg(contoursplot, "eps");}
6355 	if(!strcmp(name,"Read")) {  readAGabeditDlg(contoursplot);}
6356 	if(!strcmp(name,"Save")) {  saveAsGabeditDlg(contoursplot);}
6357 	if(!strcmp(name,"Help")) {  gabedit_contoursplot_help();}
6358 	if(!strcmp(name,"Close")) {  destroy_contoursplot_window(contoursplot);}
6359 }
6360 /*--------------------------------------------------------------------*/
6361 static GtkActionEntry gtkActionEntries[] =
6362 {
6363 	{"Set", NULL, N_("_Set")},
6364 	{"SetTicks", NULL, N_("_Ticks"), NULL, "Ticks", G_CALLBACK (activate_action) },
6365 	{"SetMargins", NULL, N_("_Margins"), NULL, "Margins", G_CALLBACK (activate_action) },
6366 	{"SetRanges", NULL, N_("_Ranges"), NULL, "Ranges", G_CALLBACK (activate_action) },
6367 	{"SetLabels", NULL, N_("_Labels"), NULL, "Labels", G_CALLBACK (activate_action) },
6368 	{"SetDigits", NULL, N_("_Digits"), NULL, "Digits", G_CALLBACK (activate_action) },
6369 	{"SetFontSize", NULL, N_("_Font size"), NULL, "Font size", G_CALLBACK (activate_action) },
6370 	{"SetAutoRanges", NULL, N_("_Auto ranges"), NULL, "Auto ranges", G_CALLBACK (activate_action) },
6371 	{"Render", NULL, N_("_Render")},
6372 	{"RenderGrid", NULL, N_("_Grid")},
6373 	{"RenderLegends", NULL, N_("_Legends")},
6374 	{"RenderDirections", NULL, N_("_Directions")},
6375 	{"Data", NULL, N_("_Data")},
6376 	{"DataRead", NULL, N_("_Read data from an ASCII grid file"), NULL, "Read data from an ASCII grid file", G_CALLBACK (activate_action) },
6377 	{"DataSaveAll", NULL, N_("_Save all data in an ascii grid file"), NULL, "Save all data in an ascii file", G_CALLBACK (activate_action) },
6378 	{"DataRemoveAll", NULL, N_("_Remove all data"), NULL, "Remove all data", G_CALLBACK (activate_action) },
6379 
6380 	{"Contours", NULL, N_("_Contours")},
6381 	{"ContoursSet", NULL, N_("_Set contours values"), NULL, "Set contours values", G_CALLBACK (activate_action) },
6382 	{"ContoursBuildLabelPositions", NULL, N_("Reset _label positions"), NULL, "Reset label positions", G_CALLBACK (activate_action) },
6383 	{"ContoursDelete", NULL, N_("_Delete all"), NULL, "Delete all", G_CALLBACK (activate_action) },
6384 
6385 	{"ColorMap", NULL, N_("Color_Map")},
6386 	{"ColorMapSet", NULL, N_("_Set colors map"), NULL, "Set colors map", G_CALLBACK (activate_action) },
6387 
6388 	{"Objects", NULL, N_("_Objects")},
6389 	{"ObjectsInsertText", NULL, N_("Insert a _text(Click in window)"), NULL, "Insert a text", G_CALLBACK (activate_action) },
6390 	{"ObjectsDeleteTexts", NULL, N_("Delete all _texts"), NULL, "Delete all texts", G_CALLBACK (activate_action) },
6391 	{"ObjectsInsertLine", NULL, N_("Insert a _line(Click in window and move)"), NULL, "Insert a line", G_CALLBACK (activate_action) },
6392 	{"ObjectsDeleteLines", NULL, N_("Delete all _lines"), NULL, "Delete all lines", G_CALLBACK (activate_action) },
6393 	{"ObjectsInsertImage", NULL, N_("Insert an _image(Click in window)"), NULL, "Insert an image", G_CALLBACK (activate_action) },
6394 	{"ObjectsInsertImageClip", NULL, N_("Insert an _image from clipboard"), NULL, "Insert an image", G_CALLBACK (activate_action) },
6395 	{"ObjectsDeleteImages", NULL, N_("Delete all _images"), NULL, "Delete all images", G_CALLBACK (activate_action) },
6396 
6397 	{"Themes", NULL, N_("_Themes")},
6398 	{"ThemesPublication", NULL, N_("_Publication"), NULL, "Publication", G_CALLBACK (activate_action) },
6399 	{"ThemesGreenBlack", NULL, N_("_Green&black"), NULL, "Green&black", G_CALLBACK (activate_action) },
6400 	{"ThemesOther", NULL, N_("_Other"), NULL, "Other", G_CALLBACK (activate_action) },
6401 
6402 	{"ScreenCapture", NULL, N_("_Screen Capture")},
6403 	{"ScreenCaptureBMP", NULL, N_("_BMP format"), NULL, "BMP format", G_CALLBACK (activate_action) },
6404 	{"ScreenCaptureJPEG", NULL, N_("_JPEG format"), NULL, "JPEG format", G_CALLBACK (activate_action) },
6405 	{"ScreenCapturePNG", NULL, N_("_PNG format"), NULL, "PNG format", G_CALLBACK (activate_action) },
6406 	{"ScreenCaptureTPNG", NULL, N_("_Transparent PNG format"), NULL, "Transparent PNG format", G_CALLBACK (activate_action) },
6407 	{"ScreenCaptureTIF", NULL, N_("_TIF format"), NULL, "TIF format", G_CALLBACK (activate_action) },
6408 	{"ScreenCaptureClipBoard", NULL, N_("_Copy to clipboard"), NULL, "Copy to clipboard", G_CALLBACK (activate_action) },
6409 	{"Export", NULL, "_Export"},
6410 	{"ExportSVG", NULL, N_("Export _SVG format"), NULL, "SVG format", G_CALLBACK (activate_action) },
6411 	{"ExportPDF", NULL, N_("Export p_df format"), NULL, "PDF format", G_CALLBACK (activate_action) },
6412 	{"ExportPS", NULL, N_("Export _postscript format"), NULL, "PS format", G_CALLBACK (activate_action) },
6413 	{"ExportEPS", NULL, N_("Export _Encapsuled postscript format"), NULL, "EPS format", G_CALLBACK (activate_action) },
6414 	{"Read", GTK_STOCK_OPEN, N_("_Read"), NULL, "Read", G_CALLBACK (activate_action) },
6415 	{"Save", GTK_STOCK_SAVE, N_("_Save"), NULL, "Save", G_CALLBACK (activate_action) },
6416 	{"Help", GTK_STOCK_HELP, N_("_Help"), NULL, "Help", G_CALLBACK (activate_action) },
6417 	{"Close", GTK_STOCK_CLOSE, N_("_Close"), NULL, "Close", G_CALLBACK (activate_action) },
6418 };
6419 
6420 
6421 static gint numberOfGtkActionEntries = G_N_ELEMENTS (gtkActionEntries);
6422 /********************************************************************************/
add_data_to_actions(GtkUIManager * manager,GtkWidget * contoursplot)6423 static void add_data_to_actions(GtkUIManager *manager, GtkWidget   *contoursplot)
6424 {
6425 	GtkAction* action = NULL;
6426 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Set/SetTicks");
6427 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6428 
6429 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Set/Margins");
6430 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6431 
6432 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Set/SetRanges");
6433 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6434 
6435 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Set/SetLabels");
6436 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6437 
6438 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Set/SetDigits");
6439 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6440 
6441 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Set/SetFontSize");
6442 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6443 
6444 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Set/SetAutoRanges");
6445 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6446 
6447 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderGrid/HGridShowMajor");
6448 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6449 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderGrid/HGridShowMinor");
6450 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6451 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderGrid/VGridShowMajor");
6452 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6453 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderGrid/VGridShowMinor");
6454 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6455 
6456 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderLegends/LegendShowLeft");
6457 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6458 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderLegends/LegendShowRight");
6459 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6460 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderLegends/LegendShowTop");
6461 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6462 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderLegends/LegendShowBottom");
6463 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6464 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderDirections/DirectionReflectX");
6465 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6466 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderDirections/DirectionReflectY");
6467 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6468 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/ShowColorMap");
6469 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6470 
6471 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/ShowLabelContours");
6472 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6473 
6474 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/DashedNegativeContours");
6475 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6476 
6477 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Data/DataRead");
6478 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6479 
6480 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Data/DataSaveAll");
6481 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6482 
6483 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Data/DataRemoveAll");
6484 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6485 
6486 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Contours/ContoursSet");
6487 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6488 
6489 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Contours/ContoursDelete");
6490 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6491 
6492 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Contours/ContoursBuildLabelPositions");
6493 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6494 
6495 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/ColorMap/ColorMapSet");
6496 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6497 
6498 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Objects/ObjectsDeleteTexts");
6499 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6500 
6501 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Objects/ObjectsInsertText");
6502 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6503 
6504 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Objects/ObjectsDeleteLines");
6505 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6506 
6507 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Objects/ObjectsInsertLine");
6508 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6509 
6510 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Objects/ObjectsInsertImage");
6511 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6512 
6513 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Objects/ObjectsInsertImageClip");
6514 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6515 
6516 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Objects/ObjectsDeleteImages");
6517 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6518 
6519 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Themes/ThemesPublication");
6520 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6521 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Themes/ThemesGreenBlack");
6522 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6523 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Themes/ThemesOther");
6524 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6525 
6526 
6527 
6528 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/ScreenCapture/ScreenCaptureBMP");
6529 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6530 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/ScreenCapture/ScreenCaptureJPEG");
6531 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6532 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/ScreenCapture/ScreenCapturePNG");
6533 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6534 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/ScreenCapture/ScreenCaptureTPNG");
6535 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6536 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/ScreenCapture/ScreenCaptureTIF");
6537 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6538 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/ScreenCapture/ScreenCaptureClipBoard");
6539 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6540 
6541 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Export/ExportSVG");
6542 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6543 
6544 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Export/ExportPDF");
6545 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6546 
6547 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Export/ExportPS");
6548 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6549 
6550 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Export/ExportEPS");
6551 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6552 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Read");
6553 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6554 
6555 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Save");
6556 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6557 
6558 
6559 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Help");
6560 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6561 
6562 	action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Close");
6563 	if(action) g_object_set_data(G_OBJECT (action), "ContoursPLOT", contoursplot);
6564 
6565 }
6566 /********************************************************************************/
6567 static const gchar *uiMenuInfo =
6568 "  <popup name=\"MenuContoursPlot\">\n"
6569 "    <separator name=\"sepMenuPopSet\" />\n"
6570 "    <menu name=\"Set\" action=\"Set\">\n"
6571 "      <menuitem name=\"SetTicks\" action=\"SetTicks\" />\n"
6572 "      <menuitem name=\"SetMargins\" action=\"SetMargins\" />\n"
6573 "      <menuitem name=\"SetRanges\" action=\"SetRanges\" />\n"
6574 "      <menuitem name=\"SetLabels\" action=\"SetLabels\" />\n"
6575 "      <menuitem name=\"SetDigits\" action=\"SetDigits\" />\n"
6576 "      <menuitem name=\"SetFontSize\" action=\"SetFontSize\" />\n"
6577 "      <separator name=\"sepSetAutoRanges\" />\n"
6578 "      <menuitem name=\"SetAutoRanges\" action=\"SetAutoRanges\" />\n"
6579 "    </menu>\n"
6580 "    <separator name=\"sepRender\" />\n"
6581 "    <menu name=\"Render\" action=\"Render\">\n"
6582 "      <menu name=\"RenderGrid\" action=\"RenderGrid\">\n"
6583 "        <menuitem name=\"HGridShowMajor\" action=\"HGridShowMajor\" />\n"
6584 "        <menuitem name=\"HGridShowMinor\" action=\"HGridShowMinor\" />\n"
6585 "        <menuitem name=\"VGridShowMajor\" action=\"VGridShowMajor\" />\n"
6586 "        <menuitem name=\"VGridShowMinor\" action=\"VGridShowMinor\" />\n"
6587 "      </menu>\n"
6588 "      <menu name=\"RenderLegends\" action=\"RenderLegends\">\n"
6589 "        <menuitem name=\"LegendShowLeft\" action=\"LegendShowLeft\" />\n"
6590 "        <menuitem name=\"LegendShowRight\" action=\"LegendShowRight\" />\n"
6591 "        <menuitem name=\"LegendShowTop\" action=\"LegendShowTop\" />\n"
6592 "        <menuitem name=\"LegendShowBottom\" action=\"LegendShowBottom\" />\n"
6593 "      </menu>\n"
6594 "      <menu name=\"RenderDirections\" action=\"RenderDirections\">\n"
6595 "        <menuitem name=\"DirectionReflectX\" action=\"DirectionReflectX\" />\n"
6596 "        <menuitem name=\"DirectionReflectY\" action=\"DirectionReflectY\" />\n"
6597 "      </menu>\n"
6598 "        <separator name=\"sepColorMap\" />\n"
6599 "        <menuitem name=\"ShowColorMap\" action=\"ShowColorMap\" />\n"
6600 "        <menuitem name=\"ShowLabelContours\" action=\"ShowLabelContours\" />\n"
6601 "        <menuitem name=\"DashedNegativeContours\" action=\"DashedNegativeContours\" />\n"
6602 "    </menu>\n"
6603 "    <separator name=\"sepData\" />\n"
6604 "    <menu name=\"Data\" action=\"Data\">\n"
6605 "        <menuitem name=\"DataRead\" action=\"DataRead\" />\n"
6606 "        <separator name=\"sepDataSaveAll\" />\n"
6607 "        <menuitem name=\"DataSaveAll\" action=\"DataSaveAll\" />\n"
6608 "        <separator name=\"sepDataRemoveAll\" />\n"
6609 "        <menuitem name=\"DataRemoveAll\" action=\"DataRemoveAll\" />\n"
6610 "    </menu>\n"
6611 "    <separator name=\"sepContours\" />\n"
6612 "    <menu name=\"Contours\" action=\"Contours\">\n"
6613 "      <menuitem name=\"ContoursSet\" action=\"ContoursSet\" />\n"
6614 "      <menuitem name=\"ContoursBuildLabelPositions\" action=\"ContoursBuildLabelPositions\" />\n"
6615 "      <menuitem name=\"ContoursDelete\" action=\"ContoursDelete\" />\n"
6616 "    </menu>\n"
6617 "    <separator name=\"sepColorMaps\" />\n"
6618 "    <menu name=\"ColorMap\" action=\"ColorMap\">\n"
6619 "      <menuitem name=\"ColorMapSet\" action=\"ColorMapSet\" />\n"
6620 "    </menu>\n"
6621 "    <separator name=\"sepObjects\" />\n"
6622 "    <menu name=\"Objects\" action=\"Objects\">\n"
6623 "      <menuitem name=\"ObjectsInsertText\" action=\"ObjectsInsertText\" />\n"
6624 "      <menuitem name=\"ObjectsDeleteTexts\" action=\"ObjectsDeleteTexts\" />\n"
6625 "      <menuitem name=\"ObjectsInsertLine\" action=\"ObjectsInsertLine\" />\n"
6626 "      <menuitem name=\"ObjectsDeleteLines\" action=\"ObjectsDeleteLines\" />\n"
6627 "      <menuitem name=\"ObjectsInsertImage\" action=\"ObjectsInsertImage\" />\n"
6628 "      <menuitem name=\"ObjectsInsertImageClip\" action=\"ObjectsInsertImageClip\" />\n"
6629 "      <menuitem name=\"ObjectsDeleteImages\" action=\"ObjectsDeleteImages\" />\n"
6630 "    </menu>\n"
6631 "    <separator name=\"sepThemes\" />\n"
6632 "    <menu name=\"Themes\" action=\"Themes\">\n"
6633 "      <menuitem name=\"ThemesPublication\" action=\"ThemesPublication\" />\n"
6634 "      <menuitem name=\"ThemesGreenBlack\" action=\"ThemesGreenBlack\" />\n"
6635 "      <menuitem name=\"ThemesOther\" action=\"ThemesOther\" />\n"
6636 "    </menu>\n"
6637 "    <separator name=\"sepScreenCapture\" />\n"
6638 "    <menu name=\"ScreenCapture\" action=\"ScreenCapture\">\n"
6639 "      <menuitem name=\"ScreenCaptureBMP\" action=\"ScreenCaptureBMP\" />\n"
6640 "      <menuitem name=\"ScreenCaptureJPEG\" action=\"ScreenCaptureJPEG\" />\n"
6641 "      <menuitem name=\"ScreenCapturePNG\" action=\"ScreenCapturePNG\" />\n"
6642 "      <menuitem name=\"ScreenCaptureTPNG\" action=\"ScreenCaptureTPNG\" />\n"
6643 "      <menuitem name=\"ScreenCaptureTIF\" action=\"ScreenCaptureTIF\" />\n"
6644 "      <menuitem name=\"ScreenCaptureClipBoard\" action=\"ScreenCaptureClipBoard\" />\n"
6645 "    </menu>\n"
6646 "    <separator name=\"sepExport\" />\n"
6647 "    <menu name=\"Export\" action=\"Export\">\n"
6648 "      <menuitem name=\"ExportSVG\" action=\"ExportSVG\" />\n"
6649 "      <menuitem name=\"ExportPDF\" action=\"ExportPDF\" />\n"
6650 "      <menuitem name=\"ExportPS\" action=\"ExportPS\" />\n"
6651 "      <menuitem name=\"ExportEPS\" action=\"ExportEPS\" />\n"
6652 "    </menu>\n"
6653 "    <separator name=\"sepRead\" />\n"
6654 "      <menuitem name=\"Read\" action=\"Read\" />\n"
6655 "    <separator name=\"sepSave\" />\n"
6656 "      <menuitem name=\"Save\" action=\"Save\" />\n"
6657 "    <separator name=\"sepHelp\" />\n"
6658 "      <menuitem name=\"Help\" action=\"Help\" />\n"
6659 "    <separator name=\"sepClose\" />\n"
6660 "      <menuitem name=\"Close\" action=\"Close\" />\n"
6661 "  </popup>\n"
6662 "  <toolbar action=\"ToolbarContoursPlot\">\n"
6663 "      <toolitem name=\"SetTicks\" action=\"SetTicks\" />\n"
6664 "      <toolitem name=\"SetMargins\" action=\"SetMargins\" />\n"
6665 "      <toolitem name=\"SetRanges\" action=\"SetRanges\" />\n"
6666 "      <toolitem name=\"ContoursSet\" action=\"ContoursSet\" />\n"
6667 "      <toolitem name=\"ColorMapSet\" action=\"ColorMapSet\" />\n"
6668 "      <toolitem name=\"ScreenCaptureBMP\" action=\"ScreenCaptureBMP\" />\n"
6669 "      <toolitem name=\"ScreenCaptureJPEG\" action=\"ScreenCaptureJPEG\" />\n"
6670 "      <toolitem name=\"ScreenCapturePNG\" action=\"ScreenCapturePNG\" />\n"
6671 "      <toolitem name=\"ScreenCaptureTPNG\" action=\"ScreenCaptureTPNG\" />\n"
6672 "      <toolitem name=\"ScreenCaptureTIF\" action=\"ScreenCaptureTIF\" />\n"
6673 "      <toolitem name=\"ScreenCaptureClipBoard\" action=\"ScreenCaptureClipBoard\" />\n"
6674 "  </toolbar>\n"
6675 ;
6676 /*****************************************************************************************/
add_widget(GtkUIManager * merge,GtkWidget * widget,GtkContainer * container)6677 static void add_widget (GtkUIManager *merge, GtkWidget   *widget, GtkContainer *container)
6678 {
6679 	GtkWidget *handlebox;
6680 
6681 	if (!GTK_IS_TOOLBAR (widget))  return;
6682 
6683 	handlebox =gtk_handle_box_new ();
6684 	g_object_ref (handlebox);
6685   	gtk_handle_box_set_handle_position  (GTK_HANDLE_BOX(handlebox),GTK_POS_TOP);
6686 	/*   GTK_SHADOW_NONE,  GTK_SHADOW_IN,  GTK_SHADOW_OUT, GTK_SHADOW_ETCHED_IN, GTK_SHADOW_ETCHED_OUT */
6687 	gtk_handle_box_set_shadow_type(GTK_HANDLE_BOX(handlebox),GTK_SHADOW_OUT);
6688 	gtk_box_pack_start (GTK_BOX (container), handlebox, FALSE, FALSE, 0);
6689 
6690 	if (GTK_IS_TOOLBAR (widget))
6691 	{
6692 		GtkToolbar *toolbar;
6693 		toolbar = GTK_TOOLBAR (widget);
6694 		gtk_toolbar_set_show_arrow (toolbar, TRUE);
6695 		gtk_toolbar_set_style(toolbar, GTK_TOOLBAR_ICONS);
6696 		gtk_toolbar_set_orientation(toolbar,  GTK_ORIENTATION_VERTICAL);
6697 	}
6698 	gtk_widget_show (widget);
6699 	gtk_container_add (GTK_CONTAINER (handlebox), widget);
6700 	gtk_widget_show (handlebox);
6701 }
6702 /*************************************************************************************************/
add_toolbar_and_popup_menu(GtkWidget * parent,GtkWidget * box)6703 static void add_toolbar_and_popup_menu(GtkWidget* parent, GtkWidget* box)
6704 {
6705 	GtkActionGroup *actionGroup = NULL;
6706 	GtkUIManager *merge = NULL;
6707 	GError *error = NULL;
6708 
6709   	merge = gtk_ui_manager_new ();
6710   	g_signal_connect_swapped (parent, "destroy", G_CALLBACK (g_object_unref), merge);
6711 
6712 	actionGroup = gtk_action_group_new ("GabeditContoursPlotActions");
6713 	gtk_action_group_set_translation_domain(actionGroup,GETTEXT_PACKAGE);
6714 	gtk_action_group_add_actions (actionGroup, gtkActionEntries, numberOfGtkActionEntries, NULL);
6715 	gtk_action_group_add_toggle_actions (actionGroup, gtkActionToggleEntries, numberOfGtkActionToggleEntries, NULL);
6716   	gtk_ui_manager_insert_action_group (merge, actionGroup, 0);
6717 
6718 	if(box) g_signal_connect (merge, "add_widget", G_CALLBACK (add_widget), box);
6719 	if (!gtk_ui_manager_add_ui_from_string (merge, uiMenuInfo, -1, &error))
6720 	{
6721 		g_message (_("building menus of contoursplot failed: %s"), error->message);
6722 		g_error_free (error);
6723 	}
6724 	g_object_set_data(G_OBJECT (parent), "Manager", merge);
6725 	add_data_to_actions(merge,parent);
6726 	init_toggle_entries (parent);
6727 }
6728 /****************************************************************************************/
gabedit_contoursplot_get_type()6729 GType gabedit_contoursplot_get_type ()
6730 {
6731 
6732 	static GType contoursplot_type = 0;
6733 	if (!contoursplot_type)
6734        	{
6735              static const GTypeInfo contoursplot_info =
6736             {
6737 	           sizeof (GabeditContoursPlotClass),
6738 	           NULL,           /* base_init */
6739 	           NULL,           /* base_finalize */
6740 	           (GClassInitFunc) gabedit_contoursplot_class_init,
6741 	           NULL,           /* class_finalize */
6742 	           NULL,           /* class_data */
6743 	           sizeof (GabeditContoursPlot),
6744 	           0,             /* n_preallocs */
6745 	           (GInstanceInitFunc) gabedit_contoursplot_init,
6746            };
6747 	   contoursplot_type = g_type_register_static (GTK_TYPE_WIDGET, "GabeditContoursPlot", &contoursplot_info, 0);
6748 	}
6749 	return contoursplot_type;
6750 }
6751 /****************************************************************************************/
gabedit_contoursplot_class_init(GabeditContoursPlotClass * class)6752 static void gabedit_contoursplot_class_init (GabeditContoursPlotClass *class)
6753 {
6754   GtkObjectClass *object_class;
6755   GtkWidgetClass *widget_class;
6756 
6757   object_class = (GtkObjectClass*) class;
6758   widget_class = (GtkWidgetClass*) class;
6759 
6760   parent_class = g_type_class_peek_parent (class);
6761 
6762   object_class->destroy = gabedit_contoursplot_destroy;
6763 
6764   widget_class->realize = gabedit_contoursplot_realize;
6765   widget_class->expose_event = gabedit_contoursplot_expose;
6766   widget_class->size_request = gabedit_contoursplot_size_request;
6767   widget_class->size_allocate = gabedit_contoursplot_size_allocate;
6768   widget_class->button_press_event = gabedit_contoursplot_button_press;
6769   widget_class->button_release_event = gabedit_contoursplot_button_release;
6770   widget_class->motion_notify_event = gabedit_contoursplot_motion_notify;
6771   widget_class->scroll_event = gabedit_contoursplot_scroll;
6772   widget_class->style_set = gabedit_contoursplot_style_set;
6773   widget_class->key_press_event = gabedit_contoursplot_key_press;
6774   widget_class->key_release_event = gabedit_contoursplot_key_release;
6775   widget_class->enter_notify_event = gabedit_contoursplot_grab;
6776   widget_class->leave_notify_event = gabedit_contoursplot_grab;
6777 }
6778 /****************************************************************************************/
gabedit_contoursplot_init(GabeditContoursPlot * contoursplot)6779 static void gabedit_contoursplot_init (GabeditContoursPlot *contoursplot)
6780 {
6781   gint i,j;
6782   g_return_if_fail (contoursplot != NULL);
6783   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
6784 
6785   contoursplot->colorsMap.type=1;
6786   for(i=0;i<3;i++)
6787   	for(j=0;j<3;j++)
6788   		contoursplot->colorsMap.colors[i][j] = 1.0;
6789  for(j=0;j<3;j++)
6790  		contoursplot->colorsMap.colors[2][j] = 0.0;
6791   contoursplot->colorsMap.colorMap = NULL;
6792 
6793   contoursplot->show_label_contours = FALSE;
6794 
6795   contoursplot->xmin=-1.0;
6796   contoursplot->xmax=1.0;
6797   contoursplot->ymin=-1.0;
6798   contoursplot->ymax=1.0;
6799 
6800   contoursplot->left_margins =0;
6801   contoursplot->top_margins =0;
6802   contoursplot->right_margins =0;
6803   contoursplot->bottom_margins =0;
6804 
6805   contoursplot->x_legends_digits=8;
6806   contoursplot->y_legends_digits=8;
6807 
6808   contoursplot->hmajor_ticks=11;
6809   contoursplot->hminor_ticks=3;
6810   contoursplot->vmajor_ticks=11;
6811   contoursplot->vminor_ticks=3;
6812   contoursplot->length_ticks=3;
6813 
6814   contoursplot->hmajor_grid=TRUE;
6815   contoursplot->hminor_grid=TRUE;
6816   contoursplot->vmajor_grid=TRUE;
6817   contoursplot->vminor_grid=TRUE;
6818 
6819   contoursplot->show_left_legends = TRUE;
6820   contoursplot->show_right_legends = FALSE;
6821   contoursplot->show_top_legends = FALSE;
6822   contoursplot->show_bottom_legends  = TRUE;
6823 
6824   contoursplot->show_colormap = FALSE;
6825   contoursplot->colormap_nlegends = 20;
6826   contoursplot->colormap_width = 0;
6827   contoursplot->colormap_height = 0;
6828   contoursplot->colormap_legends = 0;
6829   contoursplot->colormap_legends_str = 0;
6830 
6831   contoursplot->reflect_x  = FALSE;
6832   contoursplot->reflect_y  = FALSE;
6833 
6834   contoursplot->data_list=NULL;
6835 
6836   contoursplot->mouse_zoom_enabled=TRUE;
6837   contoursplot->mouse_zoom_button = 2;
6838   contoursplot->mouse_displace_enabled=FALSE;
6839   contoursplot->wheel_zoom_enabled=FALSE;
6840   contoursplot->mouse_autorange_enabled=FALSE;
6841   contoursplot->mouse_autorange_button = 1;
6842   contoursplot->mouse_distance_enabled=TRUE;
6843   contoursplot->mouse_distance_button = 1;
6844 
6845   contoursplot->h_label_str = NULL;
6846   contoursplot->v_label_str = NULL;
6847   contoursplot->h_label = NULL;
6848   contoursplot->v_label = NULL;
6849   contoursplot->h_label_width = 0;
6850   contoursplot->h_label_height = 0;
6851   contoursplot->v_label_width = 0;
6852   contoursplot->v_label_height = 0;
6853   contoursplot->font_size = 12;
6854   contoursplot->cairo_widget = NULL;
6855   contoursplot->cairo_area = NULL;
6856   contoursplot->cairo_export = NULL;
6857   contoursplot->shift_key_pressed = FALSE;
6858   contoursplot->control_key_pressed = FALSE;
6859 
6860   contoursplot->dashed_negative_contours = FALSE;
6861   contoursplot->d_key_pressed = FALSE;
6862 
6863   contoursplot->nObjectsText = 0;
6864   contoursplot->objectsText = NULL;
6865   contoursplot->t_key_pressed = FALSE;
6866   contoursplot->selected_objects_text_num = -1;
6867 
6868   contoursplot->nObjectsLine = 0;
6869   contoursplot->objectsLine = NULL;
6870   contoursplot->l_key_pressed = FALSE;
6871 
6872   contoursplot->nObjectsLine = 0;
6873   contoursplot->objectsLine = NULL;
6874   contoursplot->l_key_pressed = FALSE;
6875   contoursplot->selected_objects_image_num = -1;
6876 
6877 
6878   contoursplot->selected_objects_line_num = -1;
6879   contoursplot->selected_objects_line_type = -1;
6880   contoursplot->object_begin_point.x=-1;
6881   contoursplot->object_begin_point.y=-1;
6882   contoursplot->object_end_point.x=-1;
6883   contoursplot->object_end_point.y=-1;
6884   contoursplot->r_key_pressed = FALSE;
6885 }
6886 /****************************************************************************************/
gabedit_contoursplot_new()6887 GtkWidget* gabedit_contoursplot_new ()
6888 {
6889   GabeditContoursPlot *contoursplot;
6890 
6891   contoursplot = g_object_new (GABEDIT_TYPE_ContoursPLOT, NULL);
6892 
6893   return GTK_WIDGET (contoursplot);
6894 }
6895 /****************************************************************************************/
gabedit_contoursplot_destroy(GtkObject * object)6896 static void gabedit_contoursplot_destroy (GtkObject *object)
6897 {
6898   GabeditContoursPlot *contoursplot;
6899 
6900   g_return_if_fail (object != NULL);
6901   g_return_if_fail (G_IS_OBJECT (object));
6902   g_return_if_fail (GABEDIT_IS_ContoursPLOT (object));
6903 
6904   contoursplot = GABEDIT_ContoursPLOT (object);
6905 
6906   if (contoursplot->plotting_area && G_IS_OBJECT(contoursplot->plotting_area))
6907   {
6908     g_object_unref(G_OBJECT(contoursplot->plotting_area));
6909     contoursplot->plotting_area = NULL;
6910   }
6911   if (contoursplot->old_area && G_IS_OBJECT(contoursplot->old_area))
6912   {
6913     g_object_unref(G_OBJECT(contoursplot->old_area));
6914     contoursplot->old_area = NULL;
6915   }
6916   if (contoursplot->cairo_area)
6917   {
6918     cairo_destroy (contoursplot->cairo_area);
6919     contoursplot->cairo_area = NULL;
6920   }
6921   if (contoursplot->cairo_widget)
6922   {
6923     cairo_destroy (contoursplot->cairo_widget);
6924     contoursplot->cairo_widget = NULL;
6925   }
6926 
6927   if (contoursplot->back_gc && G_IS_OBJECT(contoursplot->back_gc))
6928   {
6929     g_object_unref(contoursplot->back_gc);
6930     contoursplot->back_gc = NULL;
6931   }
6932   if (contoursplot->fore_gc && G_IS_OBJECT(contoursplot->fore_gc))
6933   {
6934     g_object_unref(contoursplot->fore_gc);
6935     contoursplot->fore_gc = NULL;
6936   }
6937 
6938   if (contoursplot->data_gc &&  G_IS_OBJECT(contoursplot->data_gc))
6939   {
6940     g_object_unref(contoursplot->data_gc);
6941     contoursplot->data_gc = NULL;
6942   }
6943 
6944   if (contoursplot->lines_gc &&  G_IS_OBJECT(contoursplot->lines_gc))
6945   {
6946     g_object_unref(contoursplot->lines_gc);
6947     contoursplot->lines_gc = NULL;
6948   }
6949 
6950 
6951   if (contoursplot->hmajor_grid_gc && G_IS_OBJECT(contoursplot->hmajor_grid_gc))
6952   {
6953     g_object_unref(contoursplot->hmajor_grid_gc);
6954     contoursplot->hmajor_grid_gc = NULL;
6955   }
6956 
6957   if (contoursplot->hminor_grid_gc && G_IS_OBJECT(contoursplot->hminor_grid_gc))
6958   {
6959     g_object_unref(contoursplot->hminor_grid_gc);
6960     contoursplot->hminor_grid_gc = NULL;
6961   }
6962 
6963   if (contoursplot->vmajor_grid_gc && G_IS_OBJECT(contoursplot->vmajor_grid_gc))
6964   {
6965     g_object_unref(contoursplot->vmajor_grid_gc);
6966     contoursplot->vmajor_grid_gc = NULL;
6967   }
6968 
6969   if (contoursplot->vminor_grid_gc && G_IS_OBJECT(contoursplot->vminor_grid_gc))
6970   {
6971     g_object_unref(contoursplot->vminor_grid_gc);
6972     contoursplot->vminor_grid_gc = NULL;
6973   }
6974 
6975   if (GTK_OBJECT_CLASS (parent_class)->destroy)
6976     (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
6977 
6978   gtk_object_destroy (object);
6979 }
6980 /****************************************************************************************/
contoursplot_get_font_size(GtkWidget * widget,PangoFontDescription * font_desc)6981 static gint contoursplot_get_font_size (GtkWidget* widget, PangoFontDescription* font_desc)
6982 {
6983 	gint font_size = 8;
6984 	if(!font_desc) return font_size;
6985 	font_size = pango_font_description_get_size (font_desc) / PANGO_SCALE;
6986 	return font_size;
6987 }
6988 /********************************************************************************/
gabedit_contoursplot_grab(GtkWidget * widget,GdkEventCrossing * event)6989 static gint gabedit_contoursplot_grab(GtkWidget* widget, GdkEventCrossing* event)
6990 {
6991 	if(!event) return FALSE;
6992 	switch(event->type)
6993 	{
6994 	      	case GDK_ENTER_NOTIFY:
6995 		      	gtk_grab_add(GTK_WIDGET (widget));
6996 			break;
6997 		case GDK_LEAVE_NOTIFY:
6998 			{
6999 				GabeditContoursPlot *contoursplot = NULL;
7000 				if(widget && GABEDIT_IS_ContoursPLOT (widget))
7001 					contoursplot = GABEDIT_ContoursPLOT (widget);
7002 		      		gtk_grab_remove(GTK_WIDGET (widget));
7003 				if(contoursplot)
7004 				{
7005   					contoursplot->shift_key_pressed = FALSE;
7006   					contoursplot->control_key_pressed = FALSE;
7007 				}
7008 			}
7009 			break;
7010 		 default:
7011 			break;
7012 	}
7013 	return TRUE;
7014 }
7015 /********************************************************************************/
gabedit_contoursplot_key_press(GtkWidget * widget,GdkEventKey * event)7016 static gint gabedit_contoursplot_key_press(GtkWidget* widget, GdkEventKey *event)
7017 {
7018 	GabeditContoursPlot *contoursplot;
7019 	g_return_val_if_fail (widget != NULL, FALSE);
7020 	g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (widget), FALSE);
7021 	g_return_val_if_fail (event != NULL, FALSE);
7022 
7023 	contoursplot = GABEDIT_ContoursPLOT (widget);
7024 
7025 	if((event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R) )
7026   		contoursplot->shift_key_pressed = TRUE;
7027 	if((event->keyval == GDK_Control_L || event->keyval == GDK_Control_R) )
7028   		contoursplot->control_key_pressed = TRUE;
7029 	if((event->keyval == GDK_Alt_L || event->keyval == GDK_Alt_L) )
7030   		contoursplot->control_key_pressed = TRUE;
7031 
7032 	if((event->keyval == GDK_d || event->keyval == GDK_D) )
7033   		contoursplot->d_key_pressed = TRUE;
7034 
7035 	if((event->keyval == GDK_c || event->keyval == GDK_C) )
7036 	{
7037 		if(contoursplot->control_key_pressed)
7038 			copyImageToClipBoard(widget);
7039 
7040 	}
7041 	if((event->keyval == GDK_v || event->keyval == GDK_V) )
7042 	{
7043 		if(contoursplot->control_key_pressed)
7044 		{
7045 			add_object_image(contoursplot, 0, 0, -1, -1, NULL);
7046     			gtk_widget_queue_draw(widget);
7047 		}
7048 	}
7049 
7050 	if((event->keyval == GDK_t || event->keyval == GDK_T) )
7051   		contoursplot->t_key_pressed = TRUE;
7052 	if((event->keyval == GDK_l || event->keyval == GDK_L) )
7053   		contoursplot->l_key_pressed = TRUE;
7054 	if((event->keyval == GDK_i || event->keyval == GDK_I) )
7055   		contoursplot->i_key_pressed = TRUE;
7056 	if((event->keyval == GDK_r || event->keyval == GDK_R) )
7057   		contoursplot->r_key_pressed = TRUE;
7058 	return TRUE;
7059 }
7060 /********************************************************************************/
gabedit_contoursplot_key_release(GtkWidget * widget,GdkEventKey * event)7061 static gint gabedit_contoursplot_key_release(GtkWidget* widget, GdkEventKey *event)
7062 {
7063 	GabeditContoursPlot *contoursplot;
7064 	g_return_val_if_fail (widget != NULL, FALSE);
7065 	g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (widget), FALSE);
7066 	g_return_val_if_fail (event != NULL, FALSE);
7067 
7068 	contoursplot = GABEDIT_ContoursPLOT (widget);
7069 
7070 	if((event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R) )
7071   		contoursplot->shift_key_pressed = FALSE;
7072 	if((event->keyval == GDK_Control_L || event->keyval == GDK_Control_R) )
7073   		contoursplot->control_key_pressed = FALSE;
7074 	if((event->keyval == GDK_Alt_L || event->keyval == GDK_Alt_R) )
7075   		contoursplot->control_key_pressed = FALSE;
7076 	if((event->keyval == GDK_d || event->keyval == GDK_D) )
7077   		contoursplot->d_key_pressed = FALSE;
7078 	if((event->keyval == GDK_t || event->keyval == GDK_T) )
7079   		contoursplot->t_key_pressed = FALSE;
7080 	if((event->keyval == GDK_l || event->keyval == GDK_L) )
7081   		contoursplot->l_key_pressed = FALSE;
7082 	if((event->keyval == GDK_i || event->keyval == GDK_I) )
7083   		contoursplot->i_key_pressed = FALSE;
7084 	if((event->keyval == GDK_r || event->keyval == GDK_R) )
7085   		contoursplot->r_key_pressed = FALSE;
7086 	return TRUE;
7087 }
7088 /****************************************************************************************/
gabedit_contoursplot_realize(GtkWidget * widget)7089 static void gabedit_contoursplot_realize (GtkWidget *widget)
7090 {
7091   GabeditContoursPlot *contoursplot;
7092   GdkWindowAttr attributes;
7093   gint attributes_mask;
7094   GdkGCValues gc_values;
7095   GdkGCValuesMask gc_values_mask;
7096   GdkColor black;
7097   GdkColor white;
7098   GdkColormap *colormap;
7099 
7100   g_return_if_fail (widget != NULL);
7101   g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
7102 
7103   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
7104   contoursplot = GABEDIT_ContoursPLOT (widget);
7105 
7106   attributes.x = widget->allocation.x;
7107   attributes.y = widget->allocation.y;
7108   attributes.width = widget->allocation.width;
7109   attributes.height = widget->allocation.height;
7110   attributes.wclass = GDK_INPUT_OUTPUT;
7111   attributes.window_type = GDK_WINDOW_CHILD;
7112   attributes.event_mask =
7113 	(  gtk_widget_get_events (widget) |
7114 	GDK_VISIBILITY_NOTIFY_MASK|
7115 	GDK_EXPOSURE_MASK |
7116 	GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK |
7117 	GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
7118 	GDK_FOCUS_CHANGE_MASK |
7119 	GDK_LEAVE_NOTIFY_MASK |
7120 	GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
7121 	GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
7122 
7123   attributes.visual = gtk_widget_get_visual (widget);
7124   attributes.colormap = gtk_widget_get_colormap (widget);
7125 
7126   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7127   widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
7128 
7129   widget->style = gtk_style_attach (widget->style, widget->window);
7130 
7131   gdk_window_set_user_data (widget->window, widget);
7132 
7133   gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
7134 
7135   colormap=gdk_drawable_get_colormap(widget->window);
7136 
7137   black.red = 0;
7138   black.green = 0;
7139   black.blue = 0;
7140   gdk_colormap_alloc_color (colormap, &black, FALSE, TRUE);
7141 
7142   white.red = 65535;
7143   white.green = 65535;
7144   white.blue = 65535;
7145   gdk_colormap_alloc_color (colormap, &white, FALSE, TRUE);
7146 
7147 
7148   gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &white);
7149   gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, &black);
7150 
7151   gc_values.foreground=white;
7152   gc_values.line_style=GDK_LINE_SOLID;
7153   gc_values.line_width=1;
7154   gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
7155   contoursplot->back_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7156 
7157   gc_values.foreground=black;
7158   gc_values.line_style=GDK_LINE_SOLID;
7159   gc_values.line_width=2;
7160   gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
7161   contoursplot->fore_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7162 
7163   gc_values.foreground=black;
7164   contoursplot->hmajor_grid_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7165   contoursplot->vmajor_grid_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7166 
7167   gc_values.foreground=black;
7168   gc_values.line_style=GDK_LINE_ON_OFF_DASH;
7169   gc_values.line_width=1;
7170   gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
7171   contoursplot->hminor_grid_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7172   contoursplot->vminor_grid_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7173 
7174   contoursplot->data_gc=gdk_gc_new (widget->window);
7175 
7176   gc_values.foreground=black;
7177   gc_values.line_style=GDK_LINE_SOLID;
7178   gc_values.line_width=2;
7179   gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
7180   contoursplot->lines_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7181 
7182   contoursplot->font_size =  contoursplot_get_font_size (widget, widget->style->font_desc);
7183 
7184   /* Create the initial legends*/
7185   contoursplot->v_legends_str = NULL;
7186   contoursplot->h_legends_str = NULL;
7187   contoursplot_build_legends(contoursplot);
7188   contoursplot_calculate_legends_sizes(contoursplot);
7189 
7190   contoursplot->colormap_legends_str = NULL;
7191   contoursplot_build_colormap_legends(contoursplot);
7192   contoursplot_calculate_colormap_sizes(contoursplot);
7193 
7194   contoursplot_calculate_sizes(contoursplot);
7195   add_toolbar_and_popup_menu(widget, NULL);
7196 }
7197 /****************************************************************************************/
reset_theme(GtkWidget * widget,gint line_width,GdkColor * foreColor,GdkColor * backColor)7198 static void reset_theme(GtkWidget *widget, gint line_width, GdkColor* foreColor, GdkColor* backColor )
7199 {
7200 	GabeditContoursPlot *contoursplot;
7201 	GdkGCValues gc_values;
7202 	GdkGCValuesMask gc_values_mask;
7203 	GdkColormap *colormap;
7204 
7205 	g_return_if_fail (widget != NULL);
7206 	g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
7207 
7208 	contoursplot = GABEDIT_ContoursPLOT (widget);
7209 
7210 	colormap=gdk_drawable_get_colormap(widget->window);
7211 
7212 	gdk_colormap_alloc_color (colormap, backColor, FALSE, TRUE);
7213 	gdk_colormap_alloc_color (colormap, foreColor, FALSE, TRUE);
7214 
7215 	gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, backColor);
7216 	gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, foreColor);
7217 
7218 	if (contoursplot->back_gc && G_IS_OBJECT(contoursplot->back_gc))
7219 	{
7220 		g_object_unref(contoursplot->back_gc);
7221 		contoursplot->back_gc = NULL;
7222 	}
7223 	if (contoursplot->fore_gc && G_IS_OBJECT(contoursplot->fore_gc))
7224 	{
7225 		g_object_unref(contoursplot->fore_gc);
7226 		contoursplot->fore_gc = NULL;
7227 	}
7228 
7229 	if (contoursplot->data_gc &&	G_IS_OBJECT(contoursplot->data_gc))
7230 	{
7231 		g_object_unref(contoursplot->data_gc);
7232 		contoursplot->data_gc = NULL;
7233 	}
7234 
7235 
7236 	if (contoursplot->hmajor_grid_gc && G_IS_OBJECT(contoursplot->hmajor_grid_gc))
7237 	{
7238 		g_object_unref(contoursplot->hmajor_grid_gc);
7239 		contoursplot->hmajor_grid_gc = NULL;
7240 	}
7241 
7242 	if (contoursplot->hminor_grid_gc && G_IS_OBJECT(contoursplot->hminor_grid_gc))
7243 	{
7244 		g_object_unref(contoursplot->hminor_grid_gc);
7245 		contoursplot->hminor_grid_gc = NULL;
7246 	}
7247 
7248 	if (contoursplot->vmajor_grid_gc && G_IS_OBJECT(contoursplot->vmajor_grid_gc))
7249 	{
7250 		g_object_unref(contoursplot->vmajor_grid_gc);
7251 		contoursplot->vmajor_grid_gc = NULL;
7252 	}
7253 
7254 	if (contoursplot->vminor_grid_gc && G_IS_OBJECT(contoursplot->vminor_grid_gc))
7255 	{
7256 		g_object_unref(contoursplot->vminor_grid_gc);
7257 		contoursplot->vminor_grid_gc = NULL;
7258 	}
7259 
7260 	gc_values.foreground=*backColor;
7261 	gc_values.line_style=GDK_LINE_SOLID;
7262 	gc_values.line_width=line_width;
7263 	gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
7264 	contoursplot->back_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7265 
7266 	gc_values.foreground=*foreColor;
7267 	gc_values.line_style=GDK_LINE_SOLID;
7268 	gc_values.line_width=line_width;
7269 	gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
7270 	contoursplot->fore_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7271 
7272 	gc_values.foreground=*foreColor;
7273 	contoursplot->hmajor_grid_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7274 	contoursplot->vmajor_grid_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7275 
7276 	gc_values.foreground=*foreColor;
7277 	gc_values.line_style=GDK_LINE_ON_OFF_DASH;
7278 	if(line_width/2>0) gc_values.line_width=line_width/2;
7279 	else gc_values.line_width=line_width;
7280 	gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
7281 	contoursplot->hminor_grid_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7282 	contoursplot->vminor_grid_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7283 
7284 	contoursplot->data_gc=gdk_gc_new (widget->window);
7285 
7286 	if (contoursplot->nObjectsLine<1)
7287 	{
7288 		if (contoursplot->lines_gc &&	G_IS_OBJECT(contoursplot->lines_gc))
7289 		{
7290 			g_object_unref(contoursplot->lines_gc);
7291 			contoursplot->lines_gc = NULL;
7292 		}
7293 		gc_values.foreground=*foreColor;
7294 		gc_values.line_style=GDK_LINE_SOLID;
7295 		gc_values.line_width=line_width;
7296 		gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
7297 		contoursplot->lines_gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
7298 	}
7299 
7300 	contoursplot_build_legends(contoursplot);
7301 	contoursplot_calculate_legends_sizes(contoursplot);
7302 	contoursplot_calculate_sizes(contoursplot);
7303 	reset_object_text_pango(contoursplot);
7304 }
7305 /****************************************************************************************/
set_theme_publication(GtkWidget * widget)7306 static void set_theme_publication(GtkWidget *widget)
7307 {
7308 	GdkColor black;
7309 	GdkColor white;
7310 	gint line_width = 2;
7311 	black.red = 0;
7312 	black.green = 0;
7313 	black.blue = 0;
7314 
7315 	white.red = 65535;
7316 	white.green = 65535;
7317 	white.blue = 65535;
7318 	reset_theme(widget, line_width, &black, &white);
7319 }
7320 /****************************************************************************************/
set_theme_green_black(GtkWidget * widget)7321 static void set_theme_green_black(GtkWidget *widget)
7322 {
7323 	GdkColor black;
7324 	GdkColor green;
7325 	gint line_width = 2;
7326 	black.red = 0;
7327 	black.green = 0;
7328 	black.blue = 0;
7329 
7330 	green.red = 0;
7331 	green.green = 65535;
7332 	green.blue = 0;
7333 	reset_theme(widget, line_width, &green, &black);
7334 }
7335 /****************************************************************************************/
theme_line_width_changed_value(GtkSpinButton * spinbutton,gpointer user_data)7336 static void theme_line_width_changed_value(GtkSpinButton *spinbutton, gpointer user_data)
7337 {
7338 	if(user_data && G_IS_OBJECT(user_data))
7339 	{
7340 		GtkWidget* widget = GTK_WIDGET(user_data);
7341 		GdkColor foreColor;
7342 		GdkColor backColor;
7343 		GdkGCValues gc_values;
7344 		gint line_width = 1;
7345 		GabeditContoursPlot* contoursplot = NULL;
7346 		GdkColormap *colormap;
7347 
7348   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
7349 		contoursplot = GABEDIT_ContoursPLOT(widget);
7350    		colormap  = gdk_window_get_colormap(widget->window);
7351 
7352 		gdk_gc_get_values(contoursplot->back_gc, &gc_values);
7353         	gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&backColor);
7354 		gdk_gc_get_values(contoursplot->fore_gc, &gc_values);
7355         	gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&foreColor);
7356 		line_width=gc_values.line_width;
7357 		line_width = gtk_spin_button_get_value(spinbutton);
7358 		reset_theme(widget, line_width, &foreColor, &backColor);
7359 	}
7360 }
7361 /****************************************************************************************/
theme_back_color_changed_value(GtkColorButton * colorbutton,gpointer user_data)7362 static void theme_back_color_changed_value(GtkColorButton  *colorbutton, gpointer user_data)
7363 {
7364 	if(user_data && G_IS_OBJECT(user_data))
7365 	{
7366 		GtkWidget* widget = GTK_WIDGET(user_data);
7367 		GdkColor foreColor;
7368 		GdkColor backColor;
7369 		GdkGCValues gc_values;
7370 		gint line_width = 1;
7371 		GabeditContoursPlot* contoursplot = NULL;
7372 		GdkColormap *colormap;
7373 
7374   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
7375 		contoursplot = GABEDIT_ContoursPLOT(widget);
7376    		colormap  = gdk_window_get_colormap(widget->window);
7377 		gtk_color_button_get_color (colorbutton, &backColor);
7378 		gdk_gc_get_values(contoursplot->fore_gc, &gc_values);
7379         	gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&foreColor);
7380 		line_width=gc_values.line_width;
7381 		reset_theme(widget, line_width, &foreColor, &backColor);
7382 
7383 	}
7384 }
7385 /********************************************************************************************************/
theme_fore_color_changed_value(GtkColorButton * colorbutton,gpointer user_data)7386 static void theme_fore_color_changed_value(GtkColorButton  *colorbutton, gpointer user_data)
7387 {
7388 	if(user_data && G_IS_OBJECT(user_data))
7389 	{
7390 		GtkWidget* widget = GTK_WIDGET(user_data);
7391 		GdkColor foreColor;
7392 		GdkColor backColor;
7393 		GdkGCValues gc_values;
7394 		gint line_width = 1;
7395 		GabeditContoursPlot* contoursplot = NULL;
7396 		GdkColormap *colormap;
7397 
7398   		g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
7399 		contoursplot = GABEDIT_ContoursPLOT(widget);
7400    		colormap  = gdk_window_get_colormap(widget->window);
7401 		gtk_color_button_get_color (colorbutton, &foreColor);
7402 		gdk_gc_get_values(contoursplot->back_gc, &gc_values);
7403         	gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&backColor);
7404 		line_width=gc_values.line_width;
7405 		reset_theme(widget, line_width, &foreColor, &backColor);
7406 	}
7407 }
7408 /********************************************************************************************************/
set_theme_dialog(GtkWidget * widget)7409 static void set_theme_dialog(GtkWidget* widget)
7410 {
7411 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
7412 	GtkWidget* frame = NULL;
7413 	GtkWidget* hbox = NULL;
7414 	GtkWidget* hbox1 = NULL;
7415 	GtkWidget* label = NULL;
7416 	GtkWidget* spin = NULL;
7417 	GtkWidget* button = NULL;
7418 	GtkWidget* buttonBack = NULL;
7419 	GtkWidget* buttonFore = NULL;
7420 	GtkWidget* parentWindow = NULL;
7421 	GtkWidget* vbox_window = NULL;
7422 	GdkColor foreColor;
7423 	GdkColor backColor;
7424 	GdkGCValues gc_values;
7425 	gint line_width = 1;
7426 	GabeditContoursPlot* contoursplot = NULL;
7427 	GdkColormap *colormap;
7428 
7429   	g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
7430 	contoursplot = GABEDIT_ContoursPLOT(widget);
7431    	colormap  = gdk_window_get_colormap(widget->window);
7432 
7433 	gdk_gc_get_values(contoursplot->back_gc, &gc_values);
7434         gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&backColor);
7435 
7436 	gdk_gc_get_values(contoursplot->fore_gc, &gc_values);
7437         gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&foreColor);
7438 	line_width=gc_values.line_width;
7439 
7440 	gtk_window_set_title (GTK_WINDOW (window), _("Set theme"));
7441 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
7442 	gtk_window_set_modal (GTK_WINDOW (window), TRUE);
7443 
7444 	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), (gpointer)contoursplot);
7445 
7446 	vbox_window=gtk_vbox_new(FALSE, 0);
7447 	gtk_container_add(GTK_CONTAINER(window), vbox_window);
7448 	gtk_widget_show(vbox_window);
7449 
7450 	hbox1=gtk_hbox_new(FALSE, 0);
7451 	gtk_box_pack_start(GTK_BOX(vbox_window), hbox1, TRUE, FALSE, 2);
7452 	gtk_widget_show(hbox1);
7453 
7454 	frame = gtk_frame_new(NULL);
7455 	gtk_box_pack_start(GTK_BOX(hbox1), frame, TRUE, FALSE, 2);
7456 	gtk_widget_show(frame);
7457 
7458 	hbox=gtk_hbox_new(FALSE, 0);
7459 	gtk_container_add(GTK_CONTAINER(frame), hbox);
7460 	gtk_widget_show(hbox);
7461 
7462 	label=gtk_label_new(_("Line width :"));
7463 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
7464 	gtk_widget_show(label);
7465 
7466 	spin = gtk_spin_button_new_with_range(0, 10, 1);
7467 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), line_width);
7468 	gtk_box_pack_start(GTK_BOX(hbox), spin, TRUE, FALSE, 2);
7469 	gtk_widget_show(spin);
7470 	g_object_set_data(G_OBJECT (window), "SpinLineWidth", spin);
7471 
7472 	label=gtk_label_new(_("Background color :"));
7473 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
7474 	gtk_widget_show(label);
7475 	button = gtk_color_button_new_with_color (&backColor);
7476 	gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 2);
7477 	gtk_widget_show(button);
7478 	g_object_set_data(G_OBJECT (window), "BackColorButton", button);
7479 	buttonBack = button;
7480 
7481 	label=gtk_label_new(_("Foreground color :"));
7482 	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 2);
7483 	gtk_widget_show(label);
7484 	button = gtk_color_button_new_with_color (&foreColor);
7485 	gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 2);
7486 	gtk_widget_show(button);
7487 	g_object_set_data(G_OBJECT (window), "ForeColorButton", button);
7488 	buttonFore = button;
7489 
7490 	g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(theme_line_width_changed_value), contoursplot);
7491 	g_signal_connect(G_OBJECT(buttonBack), "color-set", G_CALLBACK(theme_back_color_changed_value), contoursplot);
7492 	g_signal_connect(G_OBJECT(buttonFore), "color-set", G_CALLBACK(theme_fore_color_changed_value), contoursplot);
7493 
7494 	parentWindow = get_parent_window(GTK_WIDGET(contoursplot));
7495 	if(parentWindow)
7496 	{
7497 		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parentWindow));
7498 	}
7499 	gtk_widget_show(window);
7500 }
7501 /****************************************************************************************/
gabedit_contoursplot_size_request(GtkWidget * widget,GtkRequisition * requisition)7502 static void gabedit_contoursplot_size_request (GtkWidget *widget, GtkRequisition *requisition)
7503 {
7504   g_return_if_fail (widget != NULL);
7505   g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
7506   g_return_if_fail (requisition != NULL);
7507 
7508   requisition->width = ContoursPLOT_DEFAULT_SIZE;
7509   requisition->height = ContoursPLOT_DEFAULT_SIZE;
7510 }
7511 /****************************************************************************************/
gabedit_contoursplot_size_allocate(GtkWidget * widget,GtkAllocation * allocation)7512 static void gabedit_contoursplot_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
7513 {
7514   GabeditContoursPlot *contoursplot;
7515 
7516   g_return_if_fail (widget != NULL);
7517   g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
7518   g_return_if_fail (allocation != NULL);
7519 
7520   widget->allocation = *allocation;
7521   contoursplot=GABEDIT_ContoursPLOT(widget);
7522 
7523   if (GTK_WIDGET_REALIZED (widget))
7524     gdk_window_move_resize (widget->window,
7525 			allocation->x,
7526 			allocation->y,
7527 			allocation->width,
7528 			allocation->height);
7529 
7530   contoursplot_calculate_sizes(contoursplot);
7531 }
7532 /****************************************************************************************/
draw_points(GtkWidget * widget,GabeditContoursPlot * contoursplot,ContoursPlotData * data)7533 static void draw_points(GtkWidget *widget, GabeditContoursPlot *contoursplot, ContoursPlotData* data)
7534 {
7535 	gint i;
7536 	gint x, y;
7537 	GdkRectangle rect;
7538 	int n;
7539 
7540 	rect.x=0;
7541 	rect.y=0;
7542 	rect.width=widget->allocation.width;
7543 	rect.height=widget->allocation.height;
7544 
7545 	for (n=0; n<data->nContours; n++)
7546 	{
7547 		gdk_gc_set_rgb_fg_color (contoursplot->data_gc, &data->contours[n].point_color);
7548 		for (i=0; i<data->contours[n].size; i++)
7549 		{
7550 		if(data->contours[n].point_size<1) continue;
7551         	value2pixel(contoursplot, data->contours[n].x[i], data->contours[n].y[i], &x, &y);
7552         	y=contoursplot->plotting_rect.height-y;
7553 		x -= data->contours[n].point_width/2;
7554 		y -= data->contours[n].point_height/2;
7555 		if(data->contours[n].point_pango)
7556 		contoursplot_cairo_layout(contoursplot, contoursplot->cairo_area,
7557                         x,
7558 			y,
7559 			data->contours[n].point_pango,FALSE,FALSE,0);
7560 		}
7561 	}
7562 }
7563 /****************************************************************************************/
draw_rectangle_gradient(GabeditContoursPlot * contoursplot,cairo_t * cr,gint x1,gint y1,gint x2,gint y2,gdouble c1[],gdouble c2[],gboolean vertical,gdouble alpha)7564 static void draw_rectangle_gradient(GabeditContoursPlot *contoursplot, cairo_t* cr, gint x1, gint y1, gint x2, gint y2, gdouble c1[], gdouble c2[], gboolean vertical, gdouble alpha)
7565 {
7566 	cairo_pattern_t *pat;
7567 	gint w = 0;
7568 	gint h = 0;
7569 	gdouble col1[3];
7570 	gdouble col2[3];
7571 	gint k;
7572 
7573 	for(k=0;k<3;k++) col1[k] = c1[k];
7574 	for(k=0;k<3;k++) col2[k] = c2[k];
7575 
7576 	if(vertical)
7577 	{
7578 		if(x2<x1)
7579 		{
7580 			gint t = x1;
7581 			x1 = x2;
7582 			x2 = t;
7583 		}
7584 		if(y2<y1)
7585 		{
7586 			gint t = y1;
7587 			y1 = y2;
7588 			y2 = t;
7589 			for(k=0;k<3;k++)
7590 			{
7591 				gdouble t = col1[k];
7592 				col1[k] = col2[k];
7593 				col2[k] = t;
7594 			}
7595 		}
7596 	}
7597 	else
7598 	{
7599 		if(y2<y1)
7600 		{
7601 			gint t = y1;
7602 			y1 = y2;
7603 			y2 = t;
7604 		}
7605 		if(x2<x1)
7606 		{
7607 			gint t = x1;
7608 			x1 = x2;
7609 			x2 = t;
7610 			for(k=0;k<3;k++)
7611 			{
7612 				gdouble t = col1[k];
7613 				col1[k] = col2[k];
7614 				col2[k] = t;
7615 			}
7616 		}
7617 	}
7618 	w = x2-x1;
7619 	h = y2-y1;
7620 
7621 	/*
7622 	printf("x1 = %d x2 = %d y1 = %d y2 = %d\n",x1,x2,y1,y2);
7623 	printf("Col1 %f %f %f\n",col1[0], col1[1], col1[2]);
7624 	printf("Col2 %f %f %f\n",col2[0], col2[1], col2[2]);
7625 	*/
7626 	if(vertical) pat = cairo_pattern_create_linear (x1,y1, x1,y2);
7627 	else pat = cairo_pattern_create_linear (x1,y1, x2,y1);
7628 	cairo_pattern_add_color_stop_rgba (pat, 0, col1[0], col1[1], col1[2],alpha);
7629 	cairo_pattern_add_color_stop_rgba (pat, 1, col2[0], col2[1], col2[2],alpha);
7630 
7631 	cairo_rectangle(cr, x1, y1, w, h);
7632 	cairo_set_source(cr, pat);
7633 	cairo_fill(cr);
7634 	cairo_stroke (cr);
7635 
7636 	if(contoursplot->cairo_export)
7637 	{
7638 		cairo_t* cr =contoursplot->cairo_export;
7639 		cairo_rectangle(cr, x1, y1, w, h);
7640 		cairo_set_source(cr, pat);
7641 		cairo_fill(cr);
7642 		cairo_stroke (cr);
7643 	}
7644 	/*
7645 	cairo_restore (cr);
7646 	*/
7647 	cairo_pattern_destroy (pat);
7648 }
7649 /****************************************************************************************/
7650 /*
7651 static void draw_rectangle_bilinear(GabeditContoursPlot *contoursplot,
7652 		gint x1, gint y1,
7653 		gint x2, gint y2,
7654 		gdouble c1[], gdouble c2[],
7655 		gdouble c3[], gdouble c4[]
7656 		)
7657 {
7658 	draw_rectangle_gradient(contoursplot, contoursplot->cairo_area, x1, y1, x2, y2, c1, c2, FALSE, 1.0);
7659 	draw_rectangle_gradient(contoursplot, contoursplot->cairo_area, x1, y1, x2, y2, c2, c3, TRUE, 0.5);
7660 	draw_rectangle_gradient(contoursplot, contoursplot->cairo_area, x1, y1, x2, y2, c3, c4, FALSE, 0.5);
7661 	draw_rectangle_gradient(contoursplot, contoursplot->cairo_area, x1, y1, x2, y2, c1, c4, TRUE, 0.5);
7662 }
7663 */
7664 /****************************************************************************************/
draw_lines(GtkWidget * widget,GabeditContoursPlot * contoursplot,ContoursPlotData * data)7665 static void draw_lines(GtkWidget *widget, GabeditContoursPlot *contoursplot, ContoursPlotData* data)
7666 {
7667 	GdkPoint* points;
7668 	gint i;
7669 	int n;
7670 
7671 	points=(GdkPoint*)g_malloc( (sizeof(GdkPoint) * 2));
7672 
7673 	for (n=0; n<data->nContours; n++)
7674 	{
7675 		gdk_gc_set_rgb_fg_color (contoursplot->data_gc, &data->contours[n].line_color);
7676 		gdk_gc_set_line_attributes (contoursplot->data_gc,
7677 				data->contours[n].line_width, data->contours[n].line_style,
7678 				GDK_CAP_ROUND, GDK_JOIN_MITER);
7679 		for (i=0; i<data->contours[n].size-1; i++)
7680 		{
7681 			if(data->contours[n].line_width<1) continue;
7682 		if(data->contours[n].index[i] != data->contours[n].index[i+1]) continue;
7683 		value2pixel(contoursplot, data->contours[n].x[i], data->contours[n].y[i],
7684 				(gint *)&points[0].x, (gint *)&points[0].y);
7685 		points[0].y=contoursplot->plotting_rect.height-points[0].y;
7686 
7687 		value2pixel(contoursplot, data->contours[n].x[i+1], data->contours[n].y[i+1],
7688 				(gint *)&points[1].x, (gint *)&points[1].y);
7689 		points[1].y=contoursplot->plotting_rect.height-points[1].y;
7690 		contoursplot_cairo_lines(contoursplot, contoursplot->cairo_area,  widget, contoursplot->data_gc, points, 2);
7691 		}
7692 	}
7693 	g_free(points);
7694 }
7695 /****************************************************************************************/
draw_zoom_rectangle(GtkWidget * widget,GabeditContoursPlot * contoursplot)7696 static void draw_zoom_rectangle(GtkWidget *widget, GabeditContoursPlot *contoursplot)
7697 {
7698 	if (!contoursplot->mouse_zoom_enabled || contoursplot->mouse_button != contoursplot->mouse_zoom_button) return;
7699 	gdk_draw_rectangle(widget->window,
7700 			contoursplot->fore_gc,
7701 			FALSE,
7702 			contoursplot->zoom_rect.x,
7703 			contoursplot->zoom_rect.y,
7704 			contoursplot->zoom_rect.width,
7705 			contoursplot->zoom_rect.height);
7706 }
7707 /****************************************************************************************/
draw_object_line_gdk(GtkWidget * widget,GabeditContoursPlot * contoursplot)7708 static void draw_object_line_gdk(GtkWidget *widget, GabeditContoursPlot *contoursplot)
7709 {
7710 	gint arrow_size = 0;
7711 	gint i = -1;
7712 	if (contoursplot->object_begin_point.x<0 || contoursplot->object_begin_point.y<0) return;
7713 	if (contoursplot->object_end_point.x<0 || contoursplot->object_end_point.y<0) return;
7714 	i = contoursplot->selected_objects_line_num;
7715 	if(i<0 && contoursplot->nObjectsLine>0) i = contoursplot->nObjectsLine-1;
7716 
7717 	if(i>-1)
7718 	{
7719 		gdk_gc_set_rgb_fg_color (contoursplot->lines_gc, &contoursplot->objectsLine[i].color);
7720 		gdk_gc_set_line_attributes (contoursplot->lines_gc,
7721 			contoursplot->objectsLine[i].width,
7722 			/* contoursplot->objectsLine[i].style, */
7723 			GDK_LINE_ON_OFF_DASH,
7724 			GDK_CAP_ROUND,
7725 			GDK_JOIN_MITER);
7726 		arrow_size = contoursplot->objectsLine[i].arrow_size;
7727 	}
7728 	gdk_draw_line(widget->window, contoursplot->lines_gc,
7729 			contoursplot->object_begin_point.x,
7730 			contoursplot->object_begin_point.y,
7731 			contoursplot->object_end_point.x,
7732 			contoursplot->object_end_point.y
7733 		     );
7734 	if(arrow_size>0)
7735 	{
7736 		gdouble x1, y1, x2, y2;
7737 		calc_arrow_vertexes(30.0, arrow_size*5.0,
7738 		(gdouble)contoursplot->object_begin_point.x,
7739 		(gdouble)contoursplot->object_begin_point.y,
7740 		(gdouble)contoursplot->object_end_point.x,
7741 		(gdouble)contoursplot->object_end_point.y,
7742 		&x1, &y1,
7743 		&x2, &y2
7744 		);
7745 		gdk_draw_line(widget->window, contoursplot->lines_gc,
7746 			(gint)x1,
7747 			(gint)y1,
7748 			contoursplot->object_end_point.x,
7749 			contoursplot->object_end_point.y
7750 		     );
7751 		gdk_draw_line(widget->window, contoursplot->lines_gc,
7752 			(gint)x2,
7753 			(gint)y2,
7754 			contoursplot->object_end_point.x,
7755 			contoursplot->object_end_point.y
7756 		     );
7757 	}
7758 }
7759 /****************************************************************************************/
get_rotated_rectangle(gint x,gint y,gint w,gint h,gdouble angle,gint * x1,gint * y1,gint * x2,gint * y2,gint * x3,gint * y3,gint * x4,gint * y4)7760 static void get_rotated_rectangle(
7761 		gint x, gint y, gint w, gint h, gdouble angle,
7762 		gint* x1, gint* y1,
7763 		gint* x2, gint* y2,
7764 		gint* x3, gint* y3,
7765 		gint* x4, gint* y4)
7766 {
7767 	gdouble a = -angle;
7768 	gdouble cosa = cos(a);
7769 	gdouble sina = sin(a);
7770 	*x1 = x; *y1 = y;
7771 	*x2 = (gint)(x+w*cosa); *y2 = (gint)(y+w*sina);
7772 	*x3 = x+(gint)(w*cosa-h*sina); *y3 = (gint)(y+w*sina+h*cosa);
7773 	*x4 = (gint)(x-h*sina); *y4 = (gint)(y+h*cosa);
7774 }
7775 /*****************************************************************************************************************/
draw_rotated_rectangle(GtkWidget * widget,GabeditContoursPlot * contoursplot,gint x,gint y,gint w,gint h,gdouble angle)7776 static void draw_rotated_rectangle(GtkWidget *widget, GabeditContoursPlot* contoursplot,
7777 		gint x, gint y, gint w, gint h, gdouble angle)
7778 {
7779 	static GdkPoint* points = NULL;
7780 	if(!points) points = g_malloc(4*sizeof(GdkPoint));
7781 	get_rotated_rectangle( x, y, w, h, angle,
7782 		&points[0].x, &points[0].y,
7783 		&points[1].x, &points[1].y,
7784 		&points[2].x, &points[2].y,
7785 		&points[3].x, &points[3].y);
7786 	gdk_draw_polygon(widget->window, contoursplot->fore_gc, FALSE, points, 4);
7787 }
7788 /****************************************************************************************/
draw_selected_objects_text_rectangle(GtkWidget * widget,GabeditContoursPlot * contoursplot)7789 static void draw_selected_objects_text_rectangle(GtkWidget *widget, GabeditContoursPlot *contoursplot)
7790 {
7791 	gint i = contoursplot->selected_objects_text_num;
7792 	gdouble angle = 0;
7793 	if(i<0 || i>=contoursplot->nObjectsText) return;
7794 	if (contoursplot->mouse_zoom_enabled && contoursplot->mouse_button == contoursplot->mouse_zoom_button) return;
7795 	/*
7796 	gdk_draw_rectangle(widget->window,
7797 			contoursplot->fore_gc,
7798 			FALSE,
7799 			contoursplot->objectsText[i].xi,
7800 			contoursplot->objectsText[i].yi,
7801 			contoursplot->objectsText[i].width,
7802 			contoursplot->objectsText[i].height);
7803 			*/
7804 	angle = contoursplot->objectsText[i].angle;
7805 	draw_rotated_rectangle(widget, contoursplot,
7806 			contoursplot->objectsText[i].xi,
7807 			contoursplot->objectsText[i].yi,
7808 			contoursplot->objectsText[i].width,
7809 			contoursplot->objectsText[i].height,
7810 			angle);
7811 }
7812 /****************************************************************************************/
draw_colormap(GtkWidget * widget,GabeditContoursPlot * contoursplot)7813 static void draw_colormap(GtkWidget *widget, GabeditContoursPlot *contoursplot)
7814 {
7815 	gint i;
7816 	GdkRectangle rect;
7817 	gint xlabel = 0;
7818 	gint xlines = 0;
7819 	gdouble dy = 0;
7820 	gint ll = 1;
7821 	ColorMap* colorMap;
7822 	GdkColor color;
7823 	gdouble C[3];
7824 	gdouble value;
7825 	gdouble vmin;
7826 	gdouble dv;
7827 	gint x1, y1, x2, y2;
7828 	gdouble col1[3]={0,0,0};
7829 	gdouble col2[3]={0,0,0};
7830 
7831 
7832 	if (!contoursplot->show_colormap) return;
7833 	colorMap =GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap;
7834 
7835   	if(!colorMap) return;
7836 	if(colorMap->numberOfColors<2) return;
7837 	rect.x=0;
7838 	rect.y=0;
7839 	rect.width=widget->allocation.width;
7840 	rect.height=widget->allocation.height;
7841 	xlabel = contoursplot->plotting_rect.x+contoursplot->plotting_rect.width+2;
7842 	xlabel += contoursplot->colormap_width/2;
7843 	ll = contoursplot->colormap_width/2-4;
7844 	if (contoursplot->y_legends_digits!=0 && contoursplot->show_right_legends)
7845 	{
7846 		xlabel += contoursplot->y_legends_width+4;
7847 		if (contoursplot->v_label && !contoursplot->show_left_legends && contoursplot->show_right_legends)
7848 			xlabel += contoursplot->v_label_height;
7849 	}
7850 	xlines = xlabel - 2 -ll;
7851 
7852 	if(contoursplot->colormap_nlegends<2) dy = 0;
7853 	else dy = contoursplot->colormap_height/(gdouble)(contoursplot->colormap_nlegends-1);
7854 
7855     	vmin = colorMap->colorValue[0].value;
7856     	dv = (colorMap->colorValue[colorMap->numberOfColors-1].value-colorMap->colorValue[0].value)/(contoursplot->colormap_nlegends-1);
7857 	x1 = xlines;
7858 	y1 = contoursplot->plotting_rect.y+contoursplot->plotting_rect.height;
7859 	for(i=0; i<contoursplot->colormap_nlegends;i++)
7860 	{
7861 		contoursplot_cairo_string(contoursplot, contoursplot->cairo_widget, widget,
7862 			contoursplot->fore_gc,
7863                        xlabel,
7864 		       contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-i*dy,
7865 				contoursplot->colormap_legends_str[i], FALSE, TRUE,0);
7866 
7867       		value = vmin + dv*i;
7868 		set_Color_From_colorMap(colorMap, C, value);
7869 		color.red=(gushort)(C[0]*65535);
7870 		color.green=(gushort)(C[1]*65535);
7871 		color.blue=(gushort)(C[2]*65535);
7872 		gdk_gc_set_rgb_fg_color (contoursplot->data_gc, &color);
7873 		gdk_gc_set_line_attributes (contoursplot->data_gc, 2, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER);
7874 		contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, GTK_WIDGET(contoursplot), contoursplot->data_gc,
7875                        		xlines, contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-i*dy,
7876                        		xlines+ll, contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-i*dy
7877 				);
7878 		if(i==0)
7879 		{
7880 			int k;
7881 			for(k=0;k<3;k++) col1[k] = C[k];
7882 			x1 = xlines;
7883 		        y1 = contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-i*dy;
7884 		}
7885 		else
7886 		{
7887 			int k;
7888 			for(k=0;k<3;k++) col2[k] = C[k];
7889 			x2 = xlines+ll;
7890 		        y2 = contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-i*dy;
7891 			/* that not works */
7892 			draw_rectangle_gradient(contoursplot, contoursplot->cairo_widget, x1, y1, x2, y2, col1, col2,TRUE,1.0);
7893 			for(k=0;k<3;k++) col1[k] = col2[k];
7894 			x1 = xlines;
7895 			y1 = y2;
7896 		}
7897 	}
7898 }
7899 /****************************************************************************************/
draw_selected_objects_image_rectangle(GtkWidget * widget,GabeditContoursPlot * contoursplot)7900 static void draw_selected_objects_image_rectangle(GtkWidget *widget, GabeditContoursPlot *contoursplot)
7901 {
7902 	gint i = contoursplot->selected_objects_image_num;
7903 	if(i<0 || i>=contoursplot->nObjectsImage) return;
7904 	if (contoursplot->mouse_zoom_enabled && contoursplot->mouse_button == contoursplot->mouse_zoom_button) return;
7905 	gdk_draw_rectangle(widget->window,
7906 			contoursplot->fore_gc,
7907 			FALSE,
7908 			contoursplot->objectsImage[i].xi,
7909 			contoursplot->objectsImage[i].yi,
7910 			contoursplot->objectsImage[i].widthi,
7911 			contoursplot->objectsImage[i].heighti);
7912 }
7913 /****************************************************************************************/
draw_distance_line(GtkWidget * widget,GabeditContoursPlot * contoursplot)7914 static void draw_distance_line(GtkWidget *widget, GabeditContoursPlot *contoursplot)
7915 {
7916 	PangoLayout *playout;
7917 	GdkRectangle rect;
7918 	gchar begin[100]=" ";
7919 	gchar end[100] = " ";
7920 	gdouble x1,y1,x2,y2;
7921 	gint x,y;
7922 
7923 
7924 	if (!contoursplot->mouse_distance_enabled || contoursplot->mouse_button != contoursplot->mouse_distance_button) return;
7925 
7926 	x=contoursplot->distance_rect.x;
7927 	y=contoursplot->distance_rect.y;
7928 	if(gabedit_contoursplot_get_point(GABEDIT_ContoursPLOT(contoursplot), x, y, &x1, &y1))
7929 		sprintf(begin,"(%f ; %f)",x1,y1);
7930 	x = contoursplot->distance_rect.x+contoursplot->distance_rect.width;
7931 	y = contoursplot->distance_rect.y+contoursplot->distance_rect.height;
7932 	if(gabedit_contoursplot_get_point(GABEDIT_ContoursPLOT(contoursplot), x, y, &x2, &y2))
7933 		sprintf(end,"(%f ; %f)",x2,y2);
7934 	rect.x=0;
7935 	rect.y=0;
7936 	rect.width=widget->allocation.width;
7937 	rect.height=widget->allocation.height;
7938 	playout=gtk_widget_create_pango_layout (widget, begin);
7939 	if(!playout) return;
7940 	gtk_paint_layout (widget->style, widget->window,
7941 			GTK_STATE_NORMAL, FALSE,
7942 			&rect, widget, NULL,
7943 			contoursplot->distance_rect.x,
7944 			contoursplot->distance_rect.y,
7945 			playout);
7946 	if (playout) g_object_unref(G_OBJECT(playout));
7947 	playout=gtk_widget_create_pango_layout (widget, end);
7948 	gtk_paint_layout (widget->style, widget->window,
7949 			GTK_STATE_NORMAL, FALSE,
7950 			&rect, widget, NULL,
7951 			contoursplot->distance_rect.x+contoursplot->distance_rect.width,
7952 			contoursplot->distance_rect.y+contoursplot->distance_rect.height,
7953 			playout);
7954 	if (playout) g_object_unref(G_OBJECT(playout));
7955 	gdk_draw_line(widget->window,
7956 			contoursplot->fore_gc,
7957 			contoursplot->distance_rect.x,
7958 			contoursplot->distance_rect.y,
7959 			contoursplot->distance_rect.x+contoursplot->distance_rect.width,
7960 			contoursplot->distance_rect.y+contoursplot->distance_rect.height);
7961 
7962 }
7963 /****************************************************************************************/
draw_hminor_ticks(GtkWidget * widget,GabeditContoursPlot * contoursplot)7964 static void draw_hminor_ticks(GtkWidget *widget, GabeditContoursPlot *contoursplot)
7965 {
7966 	gint i;
7967 	gint j;
7968 	if (contoursplot->hmajor_ticks<2 || contoursplot->hminor_ticks == 0 ) return;
7969 	for (i=0; i < contoursplot->hmajor_ticks-1; i++)
7970 	for (j=1; j <= contoursplot->hminor_ticks; j++)
7971 	{
7972 		if (contoursplot->show_bottom_legends)
7973         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
7974 			contoursplot->fore_gc,
7975 			contoursplot->plotting_rect.x+i*contoursplot->d_hminor*(contoursplot->hminor_ticks+1)+j*contoursplot->d_hminor,
7976 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height,
7977 			contoursplot->plotting_rect.x+i*contoursplot->d_hminor*(contoursplot->hminor_ticks+1)+j*contoursplot->d_hminor,
7978 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height+contoursplot->length_ticks);
7979       		if (contoursplot->show_top_legends)
7980         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
7981 			contoursplot->fore_gc,
7982 			contoursplot->plotting_rect.x+i*contoursplot->d_hminor*(contoursplot->hminor_ticks+1)+j*contoursplot->d_hminor,
7983 			contoursplot->plotting_rect.y,
7984 			contoursplot->plotting_rect.x+i*contoursplot->d_hminor*(contoursplot->hminor_ticks+1)+j*contoursplot->d_hminor,
7985 			contoursplot->plotting_rect.y-contoursplot->length_ticks);
7986       }
7987 }
7988 /****************************************************************************************/
draw_hmajor_ticks_and_xlegends(GtkWidget * widget,GabeditContoursPlot * contoursplot)7989 static void draw_hmajor_ticks_and_xlegends(GtkWidget *widget, GabeditContoursPlot *contoursplot)
7990 {
7991 	gint i;
7992 	GdkRectangle rect;
7993 
7994 	rect.x=0;
7995 	rect.y=0;
7996 	rect.width=widget->allocation.width;
7997 	rect.height=widget->allocation.height;
7998 
7999 	if (contoursplot->hmajor_ticks>1)
8000 	for (i=0; i < contoursplot->hmajor_ticks; i++)
8001 	{
8002 		gint l1 = i;
8003 		if(contoursplot->reflect_x) l1 = contoursplot->hmajor_ticks-i-1;
8004 		if (contoursplot->show_bottom_legends)
8005         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8006 			contoursplot->fore_gc,
8007 			contoursplot->plotting_rect.x+i*contoursplot->d_hmajor,
8008 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height,
8009 			contoursplot->plotting_rect.x+i*contoursplot->d_hmajor,
8010 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height+contoursplot->length_ticks*2);
8011 		if (contoursplot->show_top_legends)
8012         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8013 			contoursplot->fore_gc,
8014 			contoursplot->plotting_rect.x+i*contoursplot->d_hmajor,
8015 			contoursplot->plotting_rect.y,
8016 			contoursplot->plotting_rect.x+i*contoursplot->d_hmajor,
8017 			contoursplot->plotting_rect.y-contoursplot->length_ticks*2);
8018 
8019 		if (contoursplot->x_legends_digits!=0 && contoursplot->show_bottom_legends)
8020 		contoursplot_cairo_string(contoursplot, contoursplot->cairo_widget, widget,
8021 			contoursplot->fore_gc,
8022 			contoursplot->plotting_rect.x+i*contoursplot->d_hmajor-0.5*contoursplot->x_legends_width,
8023 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height+contoursplot->length_ticks*2,
8024 				contoursplot->h_legends_str[l1], FALSE, FALSE,0);
8025 		if (contoursplot->x_legends_digits!=0 && contoursplot->show_top_legends)
8026 		contoursplot_cairo_string(contoursplot, contoursplot->cairo_widget, widget,
8027 			contoursplot->fore_gc,
8028                         contoursplot->plotting_rect.x+i*contoursplot->d_hmajor-0.5*contoursplot->x_legends_width,
8029 			contoursplot->plotting_rect.y-contoursplot->length_ticks*2-contoursplot->x_legends_height,
8030 				contoursplot->h_legends_str[l1], FALSE, FALSE,0);
8031 	}
8032 	if ( contoursplot->h_label && contoursplot->x_legends_digits!=0 && contoursplot->show_bottom_legends)
8033 	{
8034 		contoursplot_cairo_layout(contoursplot, contoursplot->cairo_widget,
8035                         contoursplot->plotting_rect.x+0.5*contoursplot->plotting_rect.width,
8036 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height+contoursplot->length_ticks*2+contoursplot->x_legends_height,
8037 			contoursplot->h_label,TRUE,FALSE,0);
8038 	}
8039 	if (contoursplot->h_label  && contoursplot->x_legends_digits!=0 && contoursplot->show_top_legends && !contoursplot->show_bottom_legends)
8040 	{
8041 		contoursplot_cairo_layout(contoursplot, contoursplot->cairo_widget,
8042                         contoursplot->plotting_rect.x+0.5*contoursplot->plotting_rect.width,
8043 			contoursplot->plotting_rect.y-contoursplot->x_legends_height-contoursplot->length_ticks*2-contoursplot->h_label_height,
8044 			contoursplot->h_label,TRUE,FALSE,0);
8045 	}
8046 }
8047 
8048 /****************************************************************************************/
contoursplot_cairo_line_grid(GabeditContoursPlot * contoursplot,cairo_t * cr,GtkWidget * widget,GdkGC * gc,gdouble x1,gdouble y1,gdouble x2,gdouble y2)8049 static void contoursplot_cairo_line_grid(GabeditContoursPlot *contoursplot, cairo_t* cr, GtkWidget* widget, GdkGC* gc, gdouble x1,gdouble y1,gdouble x2,gdouble y2)
8050 {
8051 	gabedit_contoursplot_cairo_line(cr,  widget, gc, x1, y1, x2, y2);
8052 	if(contoursplot->cairo_export)
8053 	{
8054 		x1+= contoursplot->plotting_rect.x;
8055 		x2+= contoursplot->plotting_rect.x;
8056 		y1+= contoursplot->plotting_rect.y;
8057 		y2+= contoursplot->plotting_rect.y;
8058 		gabedit_contoursplot_cairo_line(contoursplot->cairo_export,  widget, gc,  x1, y1, x2, y2);
8059 	}
8060 }
8061 /****************************************************************************************/
draw_hminor_grid(GtkWidget * widget,GabeditContoursPlot * contoursplot)8062 static void draw_hminor_grid(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8063 {
8064 	gint i;
8065 	gint j;
8066 	if (contoursplot->hminor_grid && (contoursplot->vmajor_ticks > 1) && (contoursplot->vminor_ticks != 0))
8067 	for (i=0; i < contoursplot->vmajor_ticks-1; i++)
8068 	for (j=1; j <= contoursplot->vminor_ticks; j++)
8069 	{
8070         	contoursplot_cairo_line_grid(contoursplot, contoursplot->cairo_area, widget,
8071 			contoursplot->hminor_grid_gc,
8072 			0,
8073 			i*contoursplot->d_vmajor+j*contoursplot->d_vminor,
8074 			contoursplot->plotting_rect.width,
8075 			i*contoursplot->d_vmajor+j*contoursplot->d_vminor);
8076       }
8077 }
8078 /****************************************************************************************/
draw_hmajor_grid(GtkWidget * widget,GabeditContoursPlot * contoursplot)8079 static void draw_hmajor_grid(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8080 {
8081 	gint i;
8082 
8083 	if (contoursplot->hmajor_grid && (contoursplot->vmajor_ticks > 1) )
8084 	for (i=1; i < (contoursplot->vmajor_ticks-1); i++)
8085         	contoursplot_cairo_line_grid(contoursplot, contoursplot->cairo_area, widget,
8086 			contoursplot->hmajor_grid_gc,
8087 			0,
8088 			i*contoursplot->d_vmajor,
8089 			contoursplot->plotting_rect.width,
8090 			i*contoursplot->d_vmajor);
8091 }
8092 /****************************************************************************************/
draw_vminor_ticks(GtkWidget * widget,GabeditContoursPlot * contoursplot)8093 static void draw_vminor_ticks(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8094 {
8095 	gint i;
8096 	gint j;
8097 
8098 	if ( (contoursplot->vmajor_ticks > 1) && (contoursplot->vminor_ticks != 0) )
8099 	for (i=0; i < contoursplot->vmajor_ticks-1; i++)
8100 	for (j=1; j <= contoursplot->vminor_ticks; j++)
8101 	{
8102 		if (contoursplot->show_left_legends)
8103         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8104 			contoursplot->fore_gc,
8105 			contoursplot->plotting_rect.x,
8106 			contoursplot->plotting_rect.y+i*contoursplot->d_vminor*(contoursplot->vminor_ticks+1)+j*contoursplot->d_vminor,
8107 			contoursplot->plotting_rect.x-contoursplot->length_ticks,
8108 			contoursplot->plotting_rect.y+i*contoursplot->d_vminor*(contoursplot->vminor_ticks+1)+j*contoursplot->d_vminor);
8109       		if (contoursplot->show_right_legends)
8110         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8111 			contoursplot->fore_gc,
8112 			contoursplot->plotting_rect.x+contoursplot->plotting_rect.width,
8113 			contoursplot->plotting_rect.y+i*contoursplot->d_vminor*(contoursplot->vminor_ticks+1)+j*contoursplot->d_vminor,
8114 			contoursplot->plotting_rect.x+contoursplot->plotting_rect.width+contoursplot->length_ticks,
8115 			contoursplot->plotting_rect.y+i*contoursplot->d_vminor*(contoursplot->vminor_ticks+1)+j*contoursplot->d_vminor);
8116 	}
8117 }
8118 /****************************************************************************************/
draw_vmajor_ticks_and_ylegends(GtkWidget * widget,GabeditContoursPlot * contoursplot)8119 static void draw_vmajor_ticks_and_ylegends(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8120 {
8121 	gint i;
8122 	GdkRectangle rect;
8123 
8124 	rect.x=0;
8125 	rect.y=0;
8126 	rect.width=widget->allocation.width;
8127 	rect.height=widget->allocation.height;
8128 
8129 	if (contoursplot->vmajor_ticks>1)
8130 	for (i=0; i < contoursplot->vmajor_ticks; i++)
8131 	{
8132 		gint l1 = i;
8133 		if(contoursplot->reflect_y) l1 = contoursplot->vmajor_ticks-i-1;
8134 		if (contoursplot->show_left_legends)
8135         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8136 			contoursplot->fore_gc,
8137 			contoursplot->plotting_rect.x,
8138 			contoursplot->plotting_rect.y+i*contoursplot->d_vmajor,
8139 			contoursplot->plotting_rect.x-contoursplot->length_ticks*2,
8140 			contoursplot->plotting_rect.y+i*contoursplot->d_vmajor);
8141 		if (contoursplot->show_right_legends)
8142         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8143 			contoursplot->fore_gc,
8144 			contoursplot->plotting_rect.x+contoursplot->plotting_rect.width,
8145 			contoursplot->plotting_rect.y+i*contoursplot->d_vmajor,
8146 			contoursplot->plotting_rect.x+contoursplot->plotting_rect.width+contoursplot->length_ticks*2,
8147 			contoursplot->plotting_rect.y+i*contoursplot->d_vmajor);
8148 
8149 		if (contoursplot->y_legends_digits!=0 && contoursplot->show_left_legends)
8150 		contoursplot_cairo_string(contoursplot, contoursplot->cairo_widget, widget,
8151 			contoursplot->fore_gc,
8152                         contoursplot->plotting_rect.x-contoursplot->y_legends_width-contoursplot->length_ticks*2-1,
8153 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-i*contoursplot->d_vmajor,
8154 				contoursplot->v_legends_str[l1], FALSE, TRUE,0);
8155 		if (contoursplot->y_legends_digits!=0 && contoursplot->show_right_legends)
8156 		contoursplot_cairo_string(contoursplot, contoursplot->cairo_widget, widget,
8157 			contoursplot->fore_gc,
8158                         contoursplot->plotting_rect.x+contoursplot->plotting_rect.width+contoursplot->length_ticks*2,
8159 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-i*contoursplot->d_vmajor,
8160 				contoursplot->v_legends_str[l1], FALSE, TRUE,0);
8161 	}
8162 	if (contoursplot->v_label && contoursplot->y_legends_digits!=0 && contoursplot->show_left_legends)
8163 	{
8164 		contoursplot_cairo_layout(contoursplot, contoursplot->cairo_widget,
8165                         contoursplot->plotting_rect.x-contoursplot->y_legends_width-contoursplot->length_ticks*2-contoursplot->v_label_height,
8166 			contoursplot->plotting_rect.y+0.5*contoursplot->plotting_rect.height,
8167 			contoursplot->v_label,FALSE,TRUE,-M_PI/2);
8168 	}
8169 	if (contoursplot->v_label && contoursplot->y_legends_digits!=0 && contoursplot->show_right_legends && !contoursplot->show_left_legends)
8170 	{
8171 		contoursplot_cairo_layout(contoursplot, contoursplot->cairo_widget,
8172                         contoursplot->plotting_rect.x+contoursplot->plotting_rect.width+contoursplot->y_legends_width+contoursplot->length_ticks*2,
8173 			contoursplot->plotting_rect.y+0.5*contoursplot->plotting_rect.height,
8174 			contoursplot->v_label,FALSE,TRUE,-M_PI/2);
8175 	}
8176 }
8177 /****************************************************************************************/
draw_vminor_grid(GtkWidget * widget,GabeditContoursPlot * contoursplot)8178 static void draw_vminor_grid(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8179 {
8180 	gint i;
8181 	gint j;
8182 	if (contoursplot->vminor_grid && (contoursplot->hmajor_ticks > 1) && (contoursplot->hminor_ticks != 0) )
8183 	for (i=0; i < contoursplot->hmajor_ticks-1; i++)
8184 	for (j=1; j <= contoursplot->hminor_ticks; j++)
8185         contoursplot_cairo_line_grid(contoursplot, contoursplot->cairo_area, widget,
8186 			contoursplot->vminor_grid_gc,
8187 			i*contoursplot->d_hmajor+j*contoursplot->d_hminor,
8188 			0,
8189 			i*contoursplot->d_hmajor+j*contoursplot->d_hminor,
8190 			contoursplot->plotting_rect.height);
8191 }
8192 /****************************************************************************************/
draw_vmajor_grid(GtkWidget * widget,GabeditContoursPlot * contoursplot)8193 static void draw_vmajor_grid(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8194 {
8195 	gint i;
8196 	if (contoursplot->vmajor_grid && (contoursplot->hmajor_ticks > 1))
8197 	for (i=1; i < (contoursplot->hmajor_ticks-1); i++)
8198         contoursplot_cairo_line_grid(contoursplot, contoursplot->cairo_area, widget,
8199 			contoursplot->vmajor_grid_gc,
8200 			i*contoursplot->d_hmajor,
8201 			0,
8202 			i*contoursplot->d_hmajor,
8203 			contoursplot->plotting_rect.height);
8204 }
8205 /****************************************************************************************/
draw_objects_text(GtkWidget * widget,GabeditContoursPlot * contoursplot)8206 static void draw_objects_text(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8207 {
8208 	gint i;
8209 	for (i=0; i < contoursplot->nObjectsText; i++)
8210 	if(contoursplot->objectsText[i].pango)
8211 	{
8212 		/*
8213     		if (
8214 		!(
8215 		(contoursplot->objectsText[i].xi > contoursplot->plotting_rect.x) &&
8216          	(contoursplot->objectsText[i].xi < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8217          	(contoursplot->objectsText[i].yi > contoursplot->plotting_rect.y) &&
8218          	(contoursplot->objectsText[i].yi < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height))
8219 		)
8220 		) continue;
8221 		*/
8222 		contoursplot_cairo_layout(contoursplot, contoursplot->cairo_widget,
8223                         contoursplot->objectsText[i].xi,
8224                         contoursplot->objectsText[i].yi,
8225 			contoursplot->objectsText[i].pango,FALSE,FALSE,-contoursplot->objectsText[i].angle);
8226 	}
8227 }
8228 /****************************************************************************************/
draw_objects_line(GtkWidget * widget,GabeditContoursPlot * contoursplot)8229 static void draw_objects_line(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8230 {
8231 	gint i;
8232 	for (i=0; i < contoursplot->nObjectsLine; i++)
8233 	{
8234 		/*
8235     		if (
8236 		!(
8237 		(contoursplot->objectsLine[i].x1i > contoursplot->plotting_rect.x) &&
8238          	(contoursplot->objectsLine[i].x1i < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8239          	(contoursplot->objectsLine[i].y1i > contoursplot->plotting_rect.y) &&
8240          	(contoursplot->objectsLine[i].y1i < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height))
8241 		)
8242 		) continue;
8243     		if (
8244 		!(
8245 		(contoursplot->objectsLine[i].x2i > contoursplot->plotting_rect.x) &&
8246          	(contoursplot->objectsLine[i].x2i < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8247          	(contoursplot->objectsLine[i].y2i > contoursplot->plotting_rect.y) &&
8248          	(contoursplot->objectsLine[i].y2i < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height))
8249 		)
8250 		) continue;
8251 		*/
8252 		/* HERE change gc vlaues */
8253 		gdouble x1, x2, y1, y2;
8254 		gdk_gc_set_rgb_fg_color (contoursplot->lines_gc, &contoursplot->objectsLine[i].color);
8255 		gdk_gc_set_line_attributes (contoursplot->lines_gc,
8256 			contoursplot->objectsLine[i].width,
8257 			contoursplot->objectsLine[i].style,
8258 			GDK_CAP_ROUND,
8259 			GDK_JOIN_MITER);
8260 
8261         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8262 			contoursplot->lines_gc,
8263 			contoursplot->objectsLine[i].x1i,
8264 			contoursplot->objectsLine[i].y1i,
8265 			contoursplot->objectsLine[i].x2i,
8266 			contoursplot->objectsLine[i].y2i);
8267 		if(contoursplot->objectsLine[i].arrow_size<1) continue;
8268 		calc_arrow_vertexes(30.0, contoursplot->objectsLine[i].arrow_size*5.0,
8269 		(gdouble)contoursplot->objectsLine[i].x1i,
8270 		(gdouble)contoursplot->objectsLine[i].y1i,
8271 		(gdouble)contoursplot->objectsLine[i].x2i,
8272 		(gdouble)contoursplot->objectsLine[i].y2i,
8273 		&x1, &y1,
8274 		&x2, &y2
8275 		);
8276         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8277 			contoursplot->lines_gc,
8278 			(gint)x1,
8279 			(gint)y1,
8280 			contoursplot->objectsLine[i].x2i,
8281 			contoursplot->objectsLine[i].y2i);
8282         	contoursplot_cairo_line(contoursplot, contoursplot->cairo_widget, widget,
8283 			contoursplot->lines_gc,
8284 			(gint)x2,
8285 			(gint)y2,
8286 			contoursplot->objectsLine[i].x2i,
8287 			contoursplot->objectsLine[i].y2i);
8288 	}
8289 }
8290 /****************************************************************************************/
draw_objects_image(GtkWidget * widget,GabeditContoursPlot * contoursplot)8291 static void draw_objects_image(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8292 {
8293 	gint i;
8294 	for (i=0; i < contoursplot->nObjectsImage; i++)
8295 	if(contoursplot->objectsImage[i].image)
8296 	{
8297 		/*
8298     		if (
8299 		!(
8300 		(contoursplot->objectsImage[i].xi > contoursplot->plotting_rect.x) &&
8301          	(contoursplot->objectsImage[i].xi < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8302          	(contoursplot->objectsImage[i].yi > contoursplot->plotting_rect.y) &&
8303          	(contoursplot->objectsImage[i].yi < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height))
8304 		)
8305 		) continue;
8306 		*/
8307 		contoursplot_cairo_image(contoursplot, contoursplot->cairo_widget, widget,
8308 				contoursplot->objectsImage[i].xi , contoursplot->objectsImage[i].yi,
8309 				contoursplot->objectsImage[i].widthi, contoursplot->objectsImage[i].heighti,
8310 				contoursplot->objectsImage[i].image);
8311 	}
8312 }
8313 /****************************************************************************************/
clean_borders(GtkWidget * widget,GabeditContoursPlot * contoursplot)8314 static void clean_borders(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8315 {
8316 	if(contoursplot->cairo_export)
8317 	{
8318 		contoursplot_cairo_rectangle(contoursplot, contoursplot->cairo_export,  widget, contoursplot->back_gc,
8319 			TRUE,
8320 			0,
8321 			0,
8322 			contoursplot->plotting_rect.x,
8323 			widget->allocation.height);
8324 		contoursplot_cairo_rectangle(contoursplot, contoursplot->cairo_export,  widget, contoursplot->back_gc,
8325 			TRUE,
8326 			0,
8327 			0,
8328 			widget->allocation.width,
8329 			contoursplot->plotting_rect.y
8330 			);
8331 		contoursplot_cairo_rectangle(contoursplot, contoursplot->cairo_export,  widget, contoursplot->back_gc,
8332 			TRUE,
8333 			0,
8334 			contoursplot->plotting_rect.y+contoursplot->plotting_rect.height,
8335 			widget->allocation.width,
8336 			widget->allocation.height-contoursplot->plotting_rect.y-contoursplot->plotting_rect.height
8337 			);
8338 		contoursplot_cairo_rectangle(contoursplot, contoursplot->cairo_export,  widget, contoursplot->back_gc,
8339 			TRUE,
8340 			contoursplot->plotting_rect.x+contoursplot->plotting_rect.width,
8341 			0,
8342 			widget->allocation.width-contoursplot->plotting_rect.x-contoursplot->plotting_rect.width,
8343 			widget->allocation.height
8344 			);
8345 	}
8346 }
8347 /****************************************************************************************/
draw_borders(GtkWidget * widget,GabeditContoursPlot * contoursplot)8348 static void draw_borders(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8349 {
8350 	contoursplot_cairo_rectangle(contoursplot, contoursplot->cairo_widget,  widget,
8351 			contoursplot->fore_gc,
8352 			FALSE,
8353 			contoursplot->plotting_rect.x,
8354 			contoursplot->plotting_rect.y,
8355 			contoursplot->plotting_rect.width,
8356 			contoursplot->plotting_rect.height);
8357 }
8358 /****************************************************************************************/
draw_background(GtkWidget * widget,GabeditContoursPlot * contoursplot)8359 static void draw_background(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8360 {
8361 	GdkRectangle rect;
8362 
8363 	rect.x=0;
8364 	rect.y=0;
8365 	rect.width=widget->allocation.width;
8366 	rect.height=widget->allocation.height;
8367 
8368 	gtk_paint_flat_box (widget->style,
8369 			widget->window,
8370 			GTK_STATE_NORMAL,
8371 			GTK_SHADOW_NONE,
8372 			&rect,
8373 			widget,
8374 			NULL,
8375 			0,
8376 			0,
8377 			-1,
8378 			-1);
8379 
8380 	/* Filling the plotting area*/
8381 	contoursplot_cairo_rectangle(contoursplot, contoursplot->cairo_area,  widget, contoursplot->back_gc,
8382 			TRUE,
8383 			0,
8384 			0,
8385 			contoursplot->plotting_rect.width,
8386 			contoursplot->plotting_rect.height);
8387 	if(contoursplot->cairo_export)
8388 	{
8389 	contoursplot_cairo_rectangle(contoursplot, contoursplot->cairo_export,  widget, contoursplot->back_gc,
8390 			TRUE,
8391 			contoursplot->plotting_rect.x,
8392 			contoursplot->plotting_rect.y,
8393 			contoursplot->plotting_rect.width,
8394 			contoursplot->plotting_rect.height);
8395 	}
8396 
8397 }
8398 /****************************************************************************************/
draw_label_contours(GtkWidget * widget,GabeditContoursPlot * contoursplot)8399 static void draw_label_contours(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8400 {
8401 	gint n;
8402 	GList *current_node;
8403 	gint x,y;
8404 	PangoLayout* pango = NULL;
8405 	ContoursPlotData *data = NULL;
8406 	gint width;
8407 	gint height;
8408 
8409 	current_node=g_list_first(GABEDIT_ContoursPLOT(contoursplot)->data_list);
8410 	for (; current_node!=NULL; current_node=current_node->next)
8411 	{
8412 		data=(ContoursPlotData*)current_node->data;
8413 		for(n=0;n<data->nContours; n++)
8414 		{
8415 	  		gchar *str = NULL;
8416 
8417 			if(!data->contours[n].label) continue;
8418 			if(strlen(data->contours[n].label)<1) continue;
8419 	  		str = g_strconcat("<span>", data->contours[n].label, "</span>", NULL);
8420         		value2pixel(contoursplot, data->contours[n].xlabel, data->contours[n].ylabel, &x, &y);
8421         		y=contoursplot->plotting_rect.height-y;
8422 			pango = gtk_widget_create_pango_layout (GTK_WIDGET(contoursplot), data->contours[n].label);
8423 			pango_layout_set_alignment(pango,PANGO_ALIGN_LEFT);
8424 	  		pango_layout_set_markup(pango, str, -1);
8425 	  		g_free(str);
8426 			pango_layout_get_size(pango, &width, &height);
8427 		        width/=PANGO_SCALE;
8428 			height/=PANGO_SCALE;
8429 			y -= height/2;
8430 
8431 			contoursplot_cairo_layout(
8432 			contoursplot,
8433 			contoursplot->cairo_area,
8434                         x,
8435 			y,
8436 			pango,FALSE,FALSE,0);
8437 			g_object_unref(G_OBJECT(pango));
8438 		}
8439 	}
8440 }
8441 /**************************************************************/
8442 /*
8443 static void draw_plan_color_coded(GtkWidget* contoursplot, ContoursPlotData *data)
8444 {
8445 	gint i;
8446 	gint j;
8447 	gint k;
8448 	gdouble v1,v2,v3,v4;
8449 	gint ix1=0,iy1=0;
8450 	gint ix2=0,iy2=0;
8451 	gdouble x1,x2,y1,y2;
8452 	gdouble dx, dy;
8453 	gdouble xmin,xmax,ymin,ymax;
8454 	gint xsize,ysize;
8455 	gdouble* zValues;
8456 	gdouble c1[3];
8457 	gdouble c2[3];
8458 	gdouble c3[3];
8459 	gdouble c4[3];
8460 	gint x1p;
8461 	gint y1p;
8462 	gint x2p;
8463 	gint y2p;
8464 
8465 	xmin = data->xmin;
8466 	xmax = data->xmax;
8467 	ymin = data->ymin;
8468 	ymax = data->ymax;
8469 	xsize = data->xsize;
8470 	ysize = data->ysize;
8471 	dx = (xmax-xmin)/(xsize-1);
8472 	dy = (ymax-ymin)/(ysize-1);
8473 	zValues = data->zValues;
8474 
8475 	for( i = 0; i<xsize-1;i++)
8476 	{
8477 		for( j = 0; j<ysize-1;j++)
8478 		{
8479 			ix1 = i;
8480 			iy1 = j;
8481 			ix2 = i+1;
8482 			iy2 = j+1;
8483 
8484 			v1 = zValues[ix1*ysize+iy1],
8485 			v2 = zValues[ix1*ysize+iy2];
8486 			v3 = zValues[ix2*ysize+iy2];
8487 			v4 = zValues[ix2*ysize+iy1];
8488 			for(k=0;k<3;k++) c1[k] = rand()/(gdouble)RAND_MAX;
8489 			for(k=0;k<3;k++) c2[k] = rand()/(gdouble)RAND_MAX;
8490 			for(k=0;k<3;k++) c3[k] = rand()/(gdouble)RAND_MAX;
8491 			for(k=0;k<3;k++) c4[k] = rand()/(gdouble)RAND_MAX;
8492 
8493 			if(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap)
8494 			{
8495 				set_Color_From_colorMap(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap, c1, v1);
8496 				set_Color_From_colorMap(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap, c2, v2);
8497 				set_Color_From_colorMap(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap, c3, v3);
8498 				set_Color_From_colorMap(GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap, c4, v4);
8499 			}
8500 			x1 = xmin+dx*i;
8501 			y1 = ymin+dy*j;
8502 			x2 = xmin+dx*(i+1);
8503 			y2 = ymin+dy*(j+1);
8504 			value2pixel(GABEDIT_ContoursPLOT(contoursplot), x1, y1, &x1p, &y1p);
8505 			value2pixel(GABEDIT_ContoursPLOT(contoursplot), x2, y2, &x2p, &y2p);
8506 			draw_rectangle_bilinear(GABEDIT_ContoursPLOT(contoursplot), x1p, y1p, x2p, y2p, c1, c2, c3, c4);
8507 		}
8508 	}
8509 }
8510 */
8511 /****************************************************************************************/
draw_data(GtkWidget * widget,GabeditContoursPlot * contoursplot)8512 static void draw_data(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8513 {
8514 	ContoursPlotData *data = NULL;
8515 	GList *current = NULL;
8516 
8517 	if(contoursplot->data_list)
8518 	for(current=g_list_first(contoursplot->data_list); current!=NULL; current=current->next)
8519 	{
8520 		data=(ContoursPlotData*)current->data;
8521 		/* draw_plan_color_coded(widget, data);*/
8522 		draw_lines(widget, contoursplot, data);
8523 		draw_points(widget, contoursplot, data);
8524 		if(contoursplot->show_label_contours)
8525 			draw_label_contours(widget, contoursplot);
8526   	}
8527 
8528 }
8529 /****************************************************************************************/
gdk_pixmap_copy(GdkPixmap * pixmap)8530 static GdkPixmap* gdk_pixmap_copy(GdkPixmap *pixmap)
8531 {
8532 	GdkPixmap *pixmap_out;
8533 	GdkGC *gc;
8534 	gint width, height, depth;
8535 
8536 	g_return_val_if_fail(pixmap != NULL, NULL);
8537 
8538 	gdk_drawable_get_size(pixmap, &width, &height);
8539 	depth = gdk_drawable_get_depth(pixmap);
8540 	pixmap_out = gdk_pixmap_new(NULL, width, height, depth);
8541 	gc = gdk_gc_new(pixmap);
8542 	gdk_draw_drawable(pixmap_out, gc, pixmap, 0, 0, 0, 0, width, height);
8543 	g_object_unref(gc);
8544 	return pixmap_out;
8545 }
8546 /****************************************************************************************/
set_old_area(GtkWidget * widget,GabeditContoursPlot * contoursplot)8547 static void set_old_area(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8548 {
8549 	if (contoursplot->old_area!=NULL) g_object_unref(G_OBJECT(contoursplot->old_area));
8550 	contoursplot->old_area=NULL;
8551 
8552 	if (GTK_WIDGET_REALIZED(widget) &&  widget->window)
8553 	{
8554 		contoursplot->old_area=gdk_pixmap_copy(widget->window);
8555 	}
8556 }
8557 /****************************************************************************************/
draw_plotting_area(GtkWidget * widget,GabeditContoursPlot * contoursplot)8558 static void draw_plotting_area(GtkWidget *widget, GabeditContoursPlot *contoursplot)
8559 {
8560 	gdk_draw_drawable (widget->window,
8561 			contoursplot->back_gc,
8562 			contoursplot->plotting_area,
8563 			0,
8564 			0,
8565 			contoursplot->plotting_rect.x,
8566 			contoursplot->plotting_rect.y,
8567 			contoursplot->plotting_rect.width,
8568 			contoursplot->plotting_rect.height);
8569 
8570 }
8571 /****************************************************************************************/
gabedit_contoursplot_draw(GtkWidget * widget)8572 static gint gabedit_contoursplot_draw (GtkWidget *widget)
8573 {
8574 	GabeditContoursPlot *contoursplot;
8575 
8576 	g_return_val_if_fail (widget != NULL, FALSE);
8577 	g_return_val_if_fail (GTK_IS_WIDGET(widget), FALSE);
8578 	if(!widget->window) return FALSE;
8579 	if(!GDK_IS_DRAWABLE (widget->window)) return FALSE;
8580 	g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (widget), FALSE);
8581 
8582 	contoursplot=GABEDIT_ContoursPLOT(widget);
8583 	if(!contoursplot->h_legends_str) return FALSE;
8584 
8585 	if (contoursplot->cairo_widget)
8586 	{
8587     		cairo_destroy (contoursplot->cairo_widget);
8588     		contoursplot->cairo_widget = gdk_cairo_create (widget->window);
8589 	}
8590 	if (contoursplot->cairo_area)
8591 	{
8592     		cairo_destroy (contoursplot->cairo_area);
8593     		contoursplot->cairo_area = gdk_cairo_create (contoursplot->plotting_area);
8594 	}
8595 
8596 	draw_background(widget, contoursplot);
8597 	draw_hminor_grid(widget, contoursplot);
8598 	draw_hmajor_grid(widget, contoursplot);
8599 	draw_vminor_grid(widget, contoursplot);
8600 	draw_vmajor_grid(widget, contoursplot);
8601 
8602 	draw_data(widget, contoursplot);
8603 
8604 	clean_borders(widget, contoursplot);/* for export */
8605 	draw_borders(widget, contoursplot);
8606 
8607 	draw_hminor_ticks(widget, contoursplot);
8608 	draw_hmajor_ticks_and_xlegends(widget, contoursplot);
8609 	draw_vminor_ticks(widget, contoursplot);
8610 	draw_vmajor_ticks_and_ylegends(widget, contoursplot);
8611 
8612 	draw_plotting_area(widget, contoursplot);
8613 
8614 	draw_colormap(widget, contoursplot);
8615 	draw_objects_image(widget, contoursplot);
8616 	draw_objects_line(widget, contoursplot);
8617 	draw_objects_text(widget, contoursplot);
8618   	set_old_area(widget, contoursplot);
8619 
8620 	return 0;
8621 }
8622 /****************************************************************************************/
gabedit_contoursplot_expose(GtkWidget * widget,GdkEventExpose * event)8623 static gint gabedit_contoursplot_expose (GtkWidget *widget, GdkEventExpose *event)
8624 {
8625 	GabeditContoursPlot *contoursplot;
8626 
8627 	g_return_val_if_fail (widget != NULL, FALSE);
8628 	g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (widget), FALSE);
8629 	/* g_return_val_if_fail (event != NULL, FALSE);*/
8630 
8631 	if (event && event->count > 0) return FALSE;
8632 	contoursplot=GABEDIT_ContoursPLOT(widget);
8633 
8634 	if (contoursplot->mouse_zoom_enabled && contoursplot->mouse_button == contoursplot->mouse_zoom_button)
8635 	{
8636 		gint width;
8637 		gint height;
8638 		gdk_drawable_get_size(contoursplot->old_area, &width, &height);
8639 		gdk_draw_drawable (widget->window,
8640 		contoursplot->back_gc,
8641 		contoursplot->old_area,
8642 		0,
8643 		0,
8644 		0,
8645 		0,
8646 		width,
8647 		height
8648 		);
8649 		draw_zoom_rectangle(widget, contoursplot);
8650 		return TRUE;
8651 	}
8652 	if (contoursplot->mouse_distance_enabled && contoursplot->mouse_button == contoursplot->mouse_distance_button)
8653 	{
8654 		gint width;
8655 		gint height;
8656 		gdk_drawable_get_size(contoursplot->old_area, &width, &height);
8657 		gdk_draw_drawable (widget->window,
8658 		contoursplot->back_gc,
8659 		contoursplot->old_area,
8660 		0,
8661 		0,
8662 		0,
8663 		0,
8664 		width,
8665 		height
8666 		);
8667 		draw_distance_line(widget, contoursplot);
8668 		return TRUE;
8669 	}
8670 	if (contoursplot->selected_objects_text_num>-1)
8671 	{
8672 		gint width;
8673 		gint height;
8674 		gdk_drawable_get_size(contoursplot->old_area, &width, &height);
8675 		gdk_draw_drawable (widget->window,
8676 		contoursplot->back_gc,
8677 		contoursplot->old_area,
8678 		0,
8679 		0,
8680 		0,
8681 		0,
8682 		width,
8683 		height
8684 		);
8685 		draw_selected_objects_text_rectangle(widget, contoursplot);
8686 		return TRUE;
8687 	}
8688 	if (contoursplot->selected_objects_image_num>-1)
8689 	{
8690 		gint width;
8691 		gint height;
8692 		gdk_drawable_get_size(contoursplot->old_area, &width, &height);
8693 		gdk_draw_drawable (widget->window,
8694 		contoursplot->back_gc,
8695 		contoursplot->old_area,
8696 		0,
8697 		0,
8698 		0,
8699 		0,
8700 		width,
8701 		height
8702 		);
8703 		draw_selected_objects_image_rectangle(widget, contoursplot);
8704 		return TRUE;
8705 	}
8706 	if (contoursplot->object_begin_point.x>-1)
8707 	{
8708 		gint width;
8709 		gint height;
8710 		gdk_drawable_get_size(contoursplot->old_area, &width, &height);
8711 		gdk_draw_drawable (widget->window,
8712 		contoursplot->back_gc,
8713 		contoursplot->old_area,
8714 		0,
8715 		0,
8716 		0,
8717 		0,
8718 		width,
8719 		height
8720 		);
8721 		draw_object_line_gdk(widget, contoursplot);
8722 		return TRUE;
8723 	}
8724 	gabedit_contoursplot_draw (widget);
8725 	return 0;
8726 }
8727 /****************************************************************************************/
get_distance_M_AB(GabeditContoursPlot * contoursplot,gint xM,gint yM,gint ixA,gint iyA,gint ixB,gint iyB)8728 static gint get_distance_M_AB(GabeditContoursPlot *contoursplot,gint xM, gint yM, gint ixA, gint iyA, gint ixB, gint iyB)
8729 {
8730 	gdouble xA = ixA;
8731 	gdouble yA = iyA;
8732 	gdouble xB = ixB;
8733 	gdouble yB = iyB;
8734 	gdouble xAB = xB -xA;
8735 	gdouble yAB = yB -yA;
8736 	gdouble AB2 = xAB*xAB + yAB*yAB;
8737 	gdouble xMA;
8738 	gdouble yMA;
8739 	gdouble MA2;
8740 	gdouble xMB;
8741 	gdouble yMB;
8742 	gdouble MB2;
8743 	gdouble xC;
8744 	gdouble yC;
8745 	gdouble xMC;
8746 	gdouble yMC;
8747 	gdouble MC2;
8748 
8749 	do{
8750 		xMA = xA -xM;
8751 		yMA = yA -yM;
8752 		MA2 = xMA*xMA + yMA*yMA;
8753 		xMB = xB -xM;
8754 		yMB = yB -yM;
8755 		MB2 = xMB*xMB + yMB*yMB;
8756 		xC = (xA + xB)/2.0;
8757 		yC = (yA + yB)/2.0;
8758 		xMC = xC - xM;
8759 		yMC = yC - yM;
8760 		MC2 = xMC*xMC + yMC*yMC;
8761 		if(MA2>MB2)
8762 		{
8763 			if(MC2<MA2)
8764 			{
8765 				xA = xC;
8766 				yA = yC;
8767 			}
8768 			else
8769 			{
8770 				xB = xC;
8771 				yB = yC;
8772 			}
8773 		}
8774 		else
8775 		{
8776 			if(MC2<MB2)
8777 			{
8778 				xB = xC;
8779 				yB = yC;
8780 			}
8781 			else
8782 			{
8783 				xA = xC;
8784 				yA = yC;
8785 			}
8786 		}
8787 		xAB = xB -xA;
8788 		yAB = yB -yA;
8789 		AB2 = xAB*xAB + yAB*yAB;
8790 	}while(AB2>1);
8791 	return (gint)sqrt(MC2);
8792 }
8793 /****************************************************************************************/
gabedit_contoursplot_double_click(GtkWidget * widget,GdkEventButton * event)8794 static gint gabedit_contoursplot_double_click (GtkWidget *widget, GdkEventButton *event)
8795 {
8796   	ContoursPlotData *data = NULL;
8797   	ContourData *contour = NULL;
8798 	GList* current = NULL;
8799 	gint x;
8800 	gint y;
8801 	gboolean OK = FALSE;
8802 	GabeditContoursPlot *contoursplot = NULL;
8803 	gint loop;
8804 	gint xOld;
8805 	gint yOld;
8806 	gint n;
8807 	gint indexOld = -1;
8808 	gint index;
8809 	gint i;
8810 
8811   	contoursplot=GABEDIT_ContoursPLOT(widget);
8812 	/* test on objects label */
8813 	i = get_object_text_num(contoursplot, event->x, event->y);
8814 	if(i>-1 && i<contoursplot->nObjectsText)
8815 	{
8816 		contoursplot->selected_objects_text_num = -1;
8817 		add_set_object_text_dialog(GTK_WIDGET(contoursplot), i, 0,0);
8818 		return TRUE;
8819 	}
8820 	/* test on objects line */
8821 	i = get_object_line_num(contoursplot, event->x, event->y);
8822 	if(i>-1 && i<contoursplot->nObjectsLine)
8823 	{
8824 		contoursplot->selected_objects_line_num = -1;
8825 		contoursplot->selected_objects_line_type = -1;
8826 		contoursplot->object_begin_point.x = -1;
8827 		contoursplot->object_begin_point.y = -1;
8828 		contoursplot->object_end_point.x = -1;
8829 		contoursplot->object_end_point.y = -1;
8830 		set_object_line_dialog(contoursplot, i);
8831 		return TRUE;
8832 	}
8833 	/* test on objects image */
8834 	i = get_object_image_num(contoursplot, event->x, event->y);
8835 	if(i>-1 && i<contoursplot->nObjectsImage)
8836 	{
8837 		contoursplot->selected_objects_image_num = -1;
8838 		contoursplot->object_begin_point.x = -1;
8839 		contoursplot->object_begin_point.y = -1;
8840 		contoursplot->object_end_point.x = -1;
8841 		contoursplot->object_end_point.y = -1;
8842 		add_set_object_image_dialog(GTK_WIDGET(contoursplot), i, 0,0);
8843 		return TRUE;
8844 	}
8845     	if (
8846 		!(
8847 		(event->x > contoursplot->plotting_rect.x) &&
8848          	(event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8849          	(event->y > contoursplot->plotting_rect.y) &&
8850          	(event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height))
8851 	)
8852 	)
8853 	{
8854 		set_all_dialog(widget);
8855 		return TRUE;
8856 	}
8857 
8858 	if(!(contoursplot->data_list)) return TRUE;
8859 	current=g_list_first(contoursplot->data_list);
8860 	for(; current != NULL; current = current->next)
8861 	{
8862 		data = (ContoursPlotData*)current->data;
8863 		xOld = 0;
8864 		yOld = 0;
8865 		for (n=0; !OK && n<data->nContours; n++)
8866 		for(loop=0;loop<data->contours[n].size;loop++)
8867 		{
8868 			contour = &data->contours[n];
8869 
8870 			index = data->contours[n].index[loop];
8871     			value2pixel(contoursplot, data->contours[n].x[loop], data->contours[n].y[loop], &x, &y);
8872 			y=contoursplot->plotting_rect.height-y;
8873 			x += contoursplot->plotting_rect.x;
8874 			y += contoursplot->plotting_rect.y;
8875 			if(loop ==0 && abs(x-event->x)<5 && abs(y-event->y)<5)
8876 			{
8877 				OK = TRUE;
8878 				break;
8879 			}
8880 			if(loop >0 && indexOld==index && get_distance_M_AB(contoursplot,(gint)event->x, (gint)event->y,  (gint)xOld, (gint)yOld, (gint)x, (gint)y)<5)
8881 			{
8882 				OK = TRUE;
8883 				break;
8884 			}
8885 			xOld = x;
8886 			yOld = y;
8887 			indexOld = index;
8888 		}
8889 		if(OK) break;
8890 	}
8891 	if(OK)
8892 	{
8893 		set_data_dialog(contoursplot,data,contour);
8894 	}
8895 	return OK;
8896 }
8897 /*********************************************************************************************************************/
popuo_menu(GtkWidget * widget,guint button,guint32 time)8898 static gboolean popuo_menu(GtkWidget* widget, guint button, guint32 time)
8899 {
8900 	GtkUIManager *manager = g_object_get_data(G_OBJECT (widget), "Manager");
8901 	GtkWidget *menu = gtk_ui_manager_get_widget (manager, "/MenuContoursPlot");
8902 	if (GTK_IS_MENU (menu))
8903 	{
8904 		gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time);
8905 		return TRUE;
8906 	}
8907 	else
8908 	{
8909 		g_message (_("popup menu of contoursplot failed"));
8910 	}
8911 	return FALSE;
8912 }
8913 /****************************************************************************************/
gabedit_contoursplot_button_press(GtkWidget * widget,GdkEventButton * event)8914 static gint gabedit_contoursplot_button_press (GtkWidget *widget, GdkEventButton *event)
8915 {
8916   GabeditContoursPlot *contoursplot;
8917 
8918   g_return_val_if_fail (widget != NULL, FALSE);
8919   g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (widget), FALSE);
8920   g_return_val_if_fail (event != NULL, FALSE);
8921 
8922   contoursplot = GABEDIT_ContoursPLOT (widget);
8923   if(event->type == GDK_2BUTTON_PRESS)
8924   {
8925 	  contoursplot->double_click = TRUE;
8926 	  return gabedit_contoursplot_double_click(widget,event);
8927   }
8928   if(event->button == 3)
8929   {
8930 	  return popuo_menu(widget, event->button, event->time);
8931   }
8932 
8933   if (contoursplot->mouse_zoom_enabled && (event->button == contoursplot->mouse_zoom_button || (event->button == 1 && contoursplot->control_key_pressed )) )
8934     if ( (event->x > contoursplot->plotting_rect.x) &&
8935          (event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8936          (event->y > contoursplot->plotting_rect.y) &&
8937          (event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height)) ){
8938       contoursplot->mouse_button=contoursplot->mouse_zoom_button;
8939 
8940       contoursplot->zoom_point.x=event->x;
8941       contoursplot->zoom_point.y=event->y;
8942 	/*set_old_area(widget, contoursplot);*/
8943   }
8944   if (contoursplot->mouse_distance_enabled && (event->button == contoursplot->mouse_distance_button && contoursplot->shift_key_pressed ) )
8945     if ( (event->x > contoursplot->plotting_rect.x) &&
8946          (event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8947          (event->y > contoursplot->plotting_rect.y) &&
8948          (event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height)) ){
8949       contoursplot->mouse_button=contoursplot->mouse_distance_button;
8950 
8951       contoursplot->distance_point.x=event->x;
8952       contoursplot->distance_point.y=event->y;
8953 	/*set_old_area(widget, contoursplot);*/
8954   }
8955 
8956   if (contoursplot->mouse_displace_enabled && (event->button == contoursplot->mouse_displace_button))
8957     if ( (event->x > contoursplot->plotting_rect.x) &&
8958          (event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8959          (event->y > contoursplot->plotting_rect.y) &&
8960          (event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height)) ){
8961       contoursplot->mouse_button=event->button;
8962 
8963       contoursplot->move_point.x=event->x;
8964       contoursplot->move_point.y=event->y;
8965   }
8966   if (contoursplot->r_key_pressed && !contoursplot->control_key_pressed){
8967 	  	gint i;
8968 		contoursplot->r_key_pressed = FALSE;
8969 		i = get_object_text_num(contoursplot, event->x, event->y);
8970 		if(i>-1) delete_object_text(GTK_WIDGET(contoursplot), i);
8971 		else
8972 		{
8973 			i = get_object_line_num(contoursplot, event->x, event->y);
8974 			if(i>-1) delete_object_line(GTK_WIDGET(contoursplot), i);
8975 			else
8976 			{
8977 				i = get_object_image_num(contoursplot, event->x, event->y);
8978 				if(i>-1) delete_object_image(GTK_WIDGET(contoursplot), i);
8979 			}
8980 		}
8981 	}
8982   if (
8983 	!contoursplot->t_key_pressed &&
8984 	!contoursplot->l_key_pressed &&
8985 	!contoursplot->i_key_pressed &&
8986 	!contoursplot->shift_key_pressed &&
8987 	!contoursplot->control_key_pressed &&
8988 	event->button != contoursplot->mouse_zoom_button)
8989 	  /*
8990     if ( (event->x > contoursplot->plotting_rect.x) &&
8991          (event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
8992          (event->y > contoursplot->plotting_rect.y) &&
8993          (event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height)) )
8994 	 */
8995     {
8996 
8997 	gdouble X, Y;
8998 	gchar txt[BSIZE];
8999 	PangoLayout *playout;
9000 	gboolean gp = gabedit_contoursplot_get_point(GABEDIT_ContoursPLOT(contoursplot), event->x, event->y, &X, &Y);
9001 	gint i;
9002 
9003 	sprintf(txt,"%s"," ");
9004 	if(gp && !contoursplot->d_key_pressed) sprintf(txt,"(%f ; %f)",X,Y);
9005 	else if(gp && contoursplot->d_key_pressed &&
9006              	(event->x > contoursplot->plotting_rect.x) &&
9007          	(event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
9008          	(event->y > contoursplot->plotting_rect.y) &&
9009          	(event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height)) )
9010 	{
9011 		gdouble z = 0;
9012 		gdouble dzdx = 0;
9013 		gdouble dzdy = 0;
9014 		gdouble d2zdx2 = 0;
9015 		gdouble d2zdy2 = 0;
9016 		gdouble d2zdxdy = 0;
9017 		gdouble evals[2] = {0,0};
9018 		gdouble evecs[2][2] = {{0,0},{0,0}};
9019 		gdouble delta;
9020 		gdouble d = 0;
9021 		gdouble precision = 1e-10;
9022 
9023 
9024 		get_interpolatedValue(GTK_WIDGET(contoursplot), NULL, X, Y, &z, &dzdx, &dzdy,
9025 				&d2zdx2, &d2zdy2, &d2zdxdy);
9026 
9027 		delta = (d2zdx2-d2zdy2)*(d2zdx2-d2zdy2)+4*d2zdxdy*d2zdxdy;
9028 		delta = sqrt(delta);
9029 		evals[0] = ((d2zdx2+d2zdy2)+delta)/2;
9030 		evals[1] = ((d2zdx2+d2zdy2)-delta)/2;
9031 
9032 		evecs[0][0] = 1.0;
9033 		evecs[0][1] = 0.0;
9034 		evecs[1][0] = 0.0;
9035 		evecs[1][1] = 1.0;
9036 		d = sqrt(d2zdxdy*d2zdxdy+(d2zdx2-evals[0])*(d2zdx2-evals[0]));
9037 		if(d>1e-10)
9038 		{
9039 			evecs[0][0] = d2zdxdy/d;
9040 			evecs[0][1] = (d2zdx2-evals[0])/d;
9041 		}
9042 		d = sqrt(d2zdxdy*d2zdxdy+(d2zdx2-evals[1])*(d2zdx2-evals[1]));
9043 		if(d>precision && fabs(evecs[0][1])>precision)
9044 		{
9045 			evecs[1][0] = d2zdxdy/d;
9046 			evecs[1][1] = -evecs[0][0]*evecs[1][0]/evecs[0][1];
9047 		}
9048 		else if(d>precision && fabs(evecs[0][0])>precision)
9049 		{
9050 			evecs[1][1] = (d2zdx2-evals[1])/d;
9051 			evecs[1][0] = -evecs[0][1]*evecs[1][1]/evecs[0][0];
9052 		}
9053 		sprintf(txt,
9054 				"(x=%f ; y=%f ; z=%f)\n(dz/dx=%f ; dz/dy=%f)\n(d2z/dx2=%f)\n(d2z/dy2=%f)\n(d2z/dxdy=%f)"
9055 				"\n(EigenHess=%f : %f %f )"
9056 				"\n(EigenHess=%f : %f %f )",
9057 				X,Y,z,dzdx, dzdy,
9058 				d2zdx2, d2zdy2, d2zdxdy,
9059 				evals[0], evecs[0][0], evecs[0][1],
9060 				evals[1], evecs[1][0], evecs[1][1]
9061 				);
9062 		if(evals[0]>=0)
9063 		gdk_draw_line(widget->window,
9064 			contoursplot->fore_gc,
9065 			event->x-(gint)(evecs[0][0]*contoursplot->plotting_rect.width/10),
9066 			event->y-(gint)(evecs[0][1]*contoursplot->plotting_rect.height/10),
9067 			event->x+(gint)(evecs[0][0]*contoursplot->plotting_rect.width/10),
9068 			event->y+(gint)(evecs[0][1]*contoursplot->plotting_rect.height/10));
9069 
9070 		if(evals[1]>=0)
9071 		gdk_draw_line(widget->window,
9072 			contoursplot->fore_gc,
9073 			event->x-(gint)(evecs[1][0]*contoursplot->plotting_rect.width/10),
9074 			event->y-(gint)(evecs[1][1]*contoursplot->plotting_rect.height/10),
9075 			event->x+(gint)(evecs[1][0]*contoursplot->plotting_rect.width/10),
9076 			event->y+(gint)(evecs[1][1]*contoursplot->plotting_rect.height/10));
9077 		if(evals[0]<0)
9078 		{
9079   			GdkGC* gc;
9080   			GdkGCValues gc_values;
9081   			GdkGCValuesMask gc_values_mask;
9082   			GdkColor col;
9083 			GdkColormap *colormap;
9084 
9085 			col.red = 65000;
9086   			col.green = 0;
9087 			col.blue = 0;
9088 
9089 			gc_values.foreground=col;
9090 			gc_values.line_style=GDK_LINE_SOLID;
9091 			gc_values.line_width=2;
9092 			gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
9093    			colormap  = gdk_window_get_colormap(widget->window);
9094 			gdk_colormap_alloc_color (colormap, &col, FALSE, TRUE);
9095 			gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
9096 			 gdk_gc_set_foreground(gc,&col);
9097 			gdk_draw_line(widget->window,gc,
9098 			event->x-(gint)(evecs[0][0]*contoursplot->plotting_rect.width/10),
9099 			event->y-(gint)(evecs[0][1]*contoursplot->plotting_rect.height/10),
9100 			event->x+(gint)(evecs[0][0]*contoursplot->plotting_rect.width/10),
9101 			event->y+(gint)(evecs[0][1]*contoursplot->plotting_rect.height/10));
9102 			g_object_unref(gc);
9103 		}
9104 		if(evals[1]<0)
9105 		{
9106   			GdkGC* gc;
9107   			GdkGCValues gc_values;
9108   			GdkGCValuesMask gc_values_mask;
9109   			GdkColor col;
9110 			GdkColormap *colormap;
9111 
9112 			col.red = 65000;
9113   			col.green = 0;
9114 			col.blue = 0;
9115 
9116 			gc_values.foreground=col;
9117 			gc_values.line_style=GDK_LINE_SOLID;
9118 			gc_values.line_width=2;
9119 			gc_values_mask=GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE | GDK_GC_LINE_WIDTH;
9120    			colormap  = gdk_window_get_colormap(widget->window);
9121 			gdk_colormap_alloc_color (colormap, &col, FALSE, TRUE);
9122 			gc=gdk_gc_new_with_values (widget->window, &gc_values, gc_values_mask);
9123 			 gdk_gc_set_foreground(gc,&col);
9124 			gdk_draw_line(widget->window,gc,
9125 			event->x-(gint)(evecs[1][0]*contoursplot->plotting_rect.width/10),
9126 			event->y-(gint)(evecs[1][1]*contoursplot->plotting_rect.height/10),
9127 			event->x+(gint)(evecs[1][0]*contoursplot->plotting_rect.width/10),
9128 			event->y+(gint)(evecs[1][1]*contoursplot->plotting_rect.height/10));
9129 			g_object_unref(gc);
9130 		}
9131 
9132 	}
9133 	playout=gtk_widget_create_pango_layout (widget, txt);
9134 	if(playout)
9135 	{
9136 		GdkRectangle rect;
9137 		rect.x=0;
9138 		rect.y=0;
9139 		rect.width=widget->allocation.width;
9140 		rect.height=widget->allocation.height;
9141 		gtk_paint_layout (widget->style, widget->window,
9142 			GTK_STATE_NORMAL, FALSE,
9143 			&rect, widget, NULL,
9144 			event->x,
9145 			event->y,
9146 			playout);
9147 		g_object_unref(G_OBJECT(playout));
9148 	}
9149 	i = get_object_text_num(contoursplot, event->x, event->y);
9150 	if(i>-1 && i<contoursplot->nObjectsText) contoursplot->selected_objects_text_num = i;
9151 	else contoursplot->selected_objects_text_num = -1;
9152 	if(contoursplot->selected_objects_text_num>-1)
9153 	{
9154 		/*set_old_area(widget, contoursplot);*/
9155     		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9156 	}
9157 	if(contoursplot->selected_objects_text_num<0)
9158 	{
9159 		i = get_object_line_num(contoursplot, event->x, event->y);
9160 		contoursplot->selected_objects_line_num = -1;
9161 		contoursplot->selected_objects_line_type = -1;
9162 		if(i>-1 && i<contoursplot->nObjectsLine)
9163 		{
9164 			gdouble xx,yy,d;
9165 			contoursplot->selected_objects_line_num = i;
9166 			contoursplot->selected_objects_line_type = 0;
9167       			contoursplot->object_begin_point.x=contoursplot->objectsLine[i].x1i;
9168       			contoursplot->object_begin_point.y=contoursplot->objectsLine[i].y1i;
9169       			contoursplot->object_end_point.x=contoursplot->objectsLine[i].x2i;
9170       			contoursplot->object_end_point.y=contoursplot->objectsLine[i].y2i;
9171 			xx = event->x-contoursplot->objectsLine[i].x1i;
9172 			yy = event->y-contoursplot->objectsLine[i].y1i;
9173 			d = xx*xx+yy*yy;
9174 			xx = event->x-contoursplot->objectsLine[i].x2i;
9175 			yy = event->y-contoursplot->objectsLine[i].y2i;
9176 			if(d<xx*xx+yy*yy) contoursplot->selected_objects_line_type = 1;
9177 			/*set_old_area(widget, contoursplot);*/
9178     			gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9179 		}
9180 
9181 	}
9182 	if(contoursplot->selected_objects_text_num<0 && contoursplot->selected_objects_line_num<0)
9183 	{
9184 		i = get_object_image_num(contoursplot, event->x, event->y);
9185 		if(i>-1 && i<contoursplot->nObjectsImage) contoursplot->selected_objects_image_num = i;
9186 		else contoursplot->selected_objects_image_num = -1;
9187 		if(contoursplot->selected_objects_image_num>-1)
9188 		{
9189 			gdouble xx = -event->x+contoursplot->objectsImage[i].xi+contoursplot->objectsImage[i].widthi;
9190 			gdouble yy = -event->y+contoursplot->objectsImage[i].yi+contoursplot->objectsImage[i].heighti;
9191 			if(xx*xx+yy*yy<
9192 			(contoursplot->objectsImage[i].widthi*contoursplot->objectsImage[i].widthi+
9193 			contoursplot->objectsImage[i].heighti*contoursplot->objectsImage[i].heighti)/100
9194 			)
9195 			{
9196       				contoursplot->object_begin_point.x=-1;
9197       				contoursplot->object_begin_point.y=-1;
9198       				contoursplot->object_end_point.x=(gint)fabs(xx);
9199       				contoursplot->object_end_point.y=(gint)fabs(yy);
9200 			}
9201 			else
9202 			{
9203       				contoursplot->object_begin_point.x=event->x-contoursplot->objectsImage[i].xi;
9204       				contoursplot->object_begin_point.y=event->y-contoursplot->objectsImage[i].yi;
9205       				contoursplot->object_end_point.x=-1;
9206       				contoursplot->object_end_point.y=-1;
9207 			}
9208 			set_old_area(widget, contoursplot);
9209     			gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9210 		}
9211 	}
9212 
9213   }
9214   if (contoursplot->t_key_pressed && !contoursplot->control_key_pressed)
9215 	  /*
9216     if ( (event->x > contoursplot->plotting_rect.x) &&
9217          (event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
9218          (event->y > contoursplot->plotting_rect.y) &&
9219          (event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height)) )
9220 	 */
9221 	 {
9222 
9223 	gdouble X, Y;
9224 
9225 	if(gabedit_contoursplot_get_point(GABEDIT_ContoursPLOT(contoursplot), event->x, event->y, &X, &Y))
9226 	{
9227 		contoursplot->t_key_pressed = FALSE;
9228 		add_set_object_text_dialog(GTK_WIDGET(contoursplot), -1, X, Y);
9229 	}
9230 
9231   }
9232   if (contoursplot->l_key_pressed && !contoursplot->control_key_pressed)
9233 	  /*
9234     if ( (event->x > contoursplot->plotting_rect.x) &&
9235          (event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
9236          (event->y > contoursplot->plotting_rect.y) &&
9237          (event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height)) )
9238 	 */
9239     {
9240 
9241 	/*set_old_area(widget, contoursplot);*/
9242 	contoursplot->l_key_pressed = FALSE;
9243       	contoursplot->object_begin_point.x=event->x;
9244       	contoursplot->object_begin_point.y=event->y;
9245       	contoursplot->object_end_point.x=-1;
9246       	contoursplot->object_end_point.y=-1;
9247 
9248   }
9249   if (contoursplot->i_key_pressed && !contoursplot->control_key_pressed)
9250 	  /*
9251     if ( (event->x > contoursplot->plotting_rect.x) &&
9252          (event->x < (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) &&
9253          (event->y > contoursplot->plotting_rect.y) &&
9254          (event->y < (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height)) )
9255 	 */
9256     {
9257 		contoursplot->i_key_pressed = FALSE;
9258 		add_set_object_image_dialog(GTK_WIDGET(contoursplot), -1, event->x, event->y);
9259 	}
9260 
9261 
9262   if ( contoursplot->mouse_autorange_enabled &&
9263       (event->button == contoursplot->mouse_autorange_button) )
9264     gabedit_contoursplot_set_autorange(contoursplot, NULL);
9265 
9266    contoursplot->double_click = FALSE;
9267 
9268   return FALSE;
9269 }
9270 /****************************************************************************************/
gabedit_contoursplot_button_release(GtkWidget * widget,GdkEventButton * event)9271 static gint gabedit_contoursplot_button_release (GtkWidget *widget, GdkEventButton *event)
9272 {
9273   GabeditContoursPlot *contoursplot;
9274   gdouble xmin, xmax, ymin, ymax;
9275   gint xleft, ytop, xright, ybottom;
9276 
9277   g_return_val_if_fail (widget != NULL, FALSE);
9278   g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (widget), FALSE);
9279   g_return_val_if_fail (event != NULL, FALSE);
9280 
9281   contoursplot = GABEDIT_ContoursPLOT (widget);
9282 
9283   contoursplot->selected_objects_text_num=-1;
9284    if (contoursplot->selected_objects_image_num>-1)
9285    {
9286 	contoursplot->object_begin_point.x=-1;
9287 	contoursplot->object_begin_point.y=-1;
9288 	contoursplot->object_end_point.x=-1;
9289 	contoursplot->object_end_point.y=-1;
9290   	contoursplot->selected_objects_image_num=-1;
9291    }
9292    if (contoursplot->selected_objects_line_num>-1)
9293    {
9294 	contoursplot->object_begin_point.x=-1;
9295 	contoursplot->object_begin_point.y=-1;
9296 	contoursplot->object_end_point.x=-1;
9297 	contoursplot->object_end_point.y=-1;
9298   	contoursplot->selected_objects_line_num=-1;
9299   	contoursplot->selected_objects_line_type=-1;
9300    }
9301 
9302 /* Zoom */
9303    if ( !contoursplot->double_click && contoursplot->mouse_zoom_enabled &&
9304        (contoursplot->mouse_button == contoursplot->mouse_zoom_button)){
9305 
9306     xleft=contoursplot->zoom_rect.x-contoursplot->plotting_rect.x;
9307     xright=contoursplot->zoom_rect.x+contoursplot->zoom_rect.width-contoursplot->plotting_rect.x;
9308     ybottom=contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-contoursplot->zoom_rect.y-contoursplot->zoom_rect.height;
9309     ytop=contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-contoursplot->zoom_rect.y;
9310 
9311     pixel2value(contoursplot, xleft, ybottom, &xmin, &ymin);
9312     pixel2value(contoursplot, xright, ytop, &xmax, &ymax);
9313 
9314     if(contoursplot->reflect_x)
9315     {
9316 	    gdouble a = xmin;
9317 	    xmin = xmax;
9318 	    xmax = a;
9319     }
9320     if(contoursplot->reflect_y)
9321     {
9322 	    gdouble a = ymin;
9323 	    ymin = ymax;
9324 	    ymax = a;
9325     }
9326 
9327     gabedit_contoursplot_set_range(contoursplot, xmin, xmax, ymin, ymax);
9328 
9329     contoursplot->mouse_button=0;
9330   }
9331 /* draw object line */
9332    if ( !contoursplot->double_click && contoursplot->object_begin_point.x>-1) {
9333 
9334 	gdouble X1, Y1;
9335 	gdouble X2, Y2;
9336 	if(gabedit_contoursplot_get_point(GABEDIT_ContoursPLOT(contoursplot), event->x, event->y, &X2, &Y2)
9337 	&& gabedit_contoursplot_get_point(GABEDIT_ContoursPLOT(contoursplot), contoursplot->object_begin_point.x, contoursplot->object_begin_point.y, &X1, &Y1))
9338 	{
9339 		contoursplot->l_key_pressed = FALSE;
9340 		add_object_line(contoursplot, X1, Y1, X2, Y2);
9341 	}
9342 	contoursplot->object_begin_point.x = -1;
9343    }
9344 /* distance */
9345    if ( !contoursplot->double_click && contoursplot->mouse_distance_enabled &&
9346        (contoursplot->mouse_button == contoursplot->mouse_distance_button)){
9347 
9348     xleft=contoursplot->distance_rect.x-contoursplot->plotting_rect.x;
9349     xright=contoursplot->distance_rect.x+contoursplot->distance_rect.width-contoursplot->plotting_rect.x;
9350     ybottom=contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-contoursplot->distance_rect.y-contoursplot->distance_rect.height;
9351     ytop=contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-contoursplot->distance_rect.y;
9352 
9353     pixel2value(contoursplot, xleft, ybottom, &xmin, &ymin);
9354     pixel2value(contoursplot, xright, ytop, &xmax, &ymax);
9355 
9356     if(contoursplot->reflect_x)
9357     {
9358 	    gdouble a = xmin;
9359 	    xmin = xmax;
9360 	    xmax = a;
9361     }
9362     if(contoursplot->reflect_y)
9363     {
9364 	    gdouble a = ymin;
9365 	    ymin = ymax;
9366 	    ymax = a;
9367     }
9368     {
9369 	GtkWidget* dialog = NULL;
9370 	gchar* tmp = NULL;
9371 	tmp = g_strdup_printf("dX = %f ; dY = %f",xmax-xmin,ymax-ymin);
9372 	dialog = gtk_message_dialog_new_with_markup (NULL,
9373 		           GTK_DIALOG_DESTROY_WITH_PARENT,
9374 		           GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
9375 			   "%s",
9376 			   tmp);
9377        gtk_dialog_run (GTK_DIALOG (dialog));
9378        gtk_widget_destroy (dialog);
9379        g_free(tmp);
9380     }
9381 
9382     /* gabedit_contoursplot_set_range(contoursplot, xmin, xmax, ymin, ymax);*/
9383 
9384     gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9385     contoursplot->mouse_button=0;
9386   }
9387    else
9388     gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9389 
9390   if (contoursplot->mouse_displace_enabled &&
9391       (event->button == contoursplot->mouse_displace_button) &&
9392       (contoursplot->mouse_button == contoursplot->mouse_displace_button) ){
9393     contoursplot->mouse_button=0;
9394   }
9395 
9396   return FALSE;
9397 }
9398 /****************************************************************************************/
gabedit_contoursplot_motion_notify(GtkWidget * widget,GdkEventMotion * event)9399 static gint gabedit_contoursplot_motion_notify (GtkWidget *widget, GdkEventMotion *event)
9400 {
9401   GabeditContoursPlot *contoursplot;
9402   gint x, y;
9403   gdouble px, py, mx, my;
9404 
9405   g_return_val_if_fail (widget != NULL, FALSE);
9406   g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (widget), FALSE);
9407   g_return_val_if_fail (event != NULL, FALSE);
9408 
9409   contoursplot = GABEDIT_ContoursPLOT (widget);
9410 
9411   x = event->x;
9412   y = event->y;
9413 
9414   if (event->is_hint || (event->window != widget->window))
9415       gdk_window_get_pointer (widget->window, (gint *)&x, (gint *)&y, NULL);
9416 
9417   if (contoursplot->selected_objects_text_num>-1)
9418   {
9419 	gint i = contoursplot->selected_objects_text_num;
9420 	ContoursPlotObjectText* objectText = &GABEDIT_ContoursPLOT(contoursplot)->objectsText[i];
9421 	gabedit_contoursplot_get_point_control (contoursplot, x, y, objectText->width, objectText->height, objectText->angle, &mx, &my);
9422 	set_object_text(contoursplot, objectText,  mx,my, objectText->angle, objectText->str);
9423 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9424   }
9425   else if (contoursplot->selected_objects_line_num>-1)
9426   {
9427 	gint i = contoursplot->selected_objects_line_num;
9428 	gdouble x1=0, y1=0, x2=0, y2=0;
9429 	ContoursPlotObjectLine* objectLine = &GABEDIT_ContoursPLOT(contoursplot)->objectsLine[i];
9430 	if(contoursplot->selected_objects_line_type==0)
9431 	{
9432       		contoursplot->object_end_point.x=x;
9433       		contoursplot->object_end_point.y=y;
9434 		gabedit_contoursplot_get_point_control (contoursplot, contoursplot->object_begin_point.x, contoursplot->object_begin_point.y,  objectLine->width,objectLine->width, 0, &x1, &y1);
9435 		gabedit_contoursplot_get_point_control (contoursplot, contoursplot->object_end_point.x, contoursplot->object_end_point.y,  objectLine->width,objectLine->width, 0, &x2, &y2);
9436 	}
9437 	else if(contoursplot->selected_objects_line_type==1)
9438 	{
9439       		contoursplot->object_begin_point.x=x;
9440       		contoursplot->object_begin_point.y=y;
9441 		gabedit_contoursplot_get_point_control (contoursplot, contoursplot->object_begin_point.x, contoursplot->object_begin_point.y,  objectLine->width,objectLine->width, 0, &x1, &y1);
9442 		gabedit_contoursplot_get_point_control (contoursplot, contoursplot->object_end_point.x, contoursplot->object_end_point.y,  objectLine->width,objectLine->width, 0, &x2, &y2);
9443 	}
9444 	set_object_line(contoursplot, objectLine,
9445 		x1, y1,
9446 		x2, y2,
9447   		objectLine->width,
9448   		objectLine->arrow_size,
9449   		objectLine->color,
9450   		objectLine->style
9451 		);
9452 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9453   }
9454   else if (contoursplot->selected_objects_image_num>-1)
9455   {
9456 	gint i = contoursplot->selected_objects_image_num;
9457 	ContoursPlotObjectImage* objectImage = &GABEDIT_ContoursPLOT(contoursplot)->objectsImage[i];
9458 	if(contoursplot->object_begin_point.x>0)
9459 	{
9460 		gint dx,dy;
9461 		x -= contoursplot->object_begin_point.x;
9462 		y -= contoursplot->object_begin_point.y;
9463 		if(x<0) x = 0;
9464 		if(y<0) y = 0;
9465 		dx = x+objectImage->widthi-widget->allocation.width;
9466 		if(dx>0) x-=dx;
9467 		dy = y+objectImage->heighti-widget->allocation.height;
9468 		if(dy>0) y-=dy;
9469 		set_object_image(contoursplot, objectImage,  x, y, objectImage->widthi, objectImage->heighti);
9470 	}
9471 	if(contoursplot->object_end_point.x>0)
9472 	{
9473 		gint w,h;
9474 		x += contoursplot->object_end_point.x;
9475 		y += contoursplot->object_end_point.y;
9476 		if(x<objectImage->xi) x = objectImage->xi+20;
9477 		if(y<objectImage->yi) y = objectImage->yi+20;
9478 		if(x>widget->allocation.width) x = widget->allocation.width;
9479 		if(y>widget->allocation.height) y = widget->allocation.height;
9480 		w = (gint)(x-objectImage->xi);
9481 		h = (gint)(y-objectImage->yi);
9482 		set_object_image(contoursplot, objectImage,  objectImage->xi, objectImage->yi, w, h);
9483 	}
9484 
9485 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9486   }
9487   else if (contoursplot->object_begin_point.x>-1)
9488   {
9489       	contoursplot->object_end_point.x=x;
9490       	contoursplot->object_end_point.y=y;
9491 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9492   }
9493 
9494   /* Zoom */
9495   if (contoursplot->mouse_zoom_enabled &&
9496       (contoursplot->mouse_button == contoursplot->mouse_zoom_button) ){
9497     if (x < contoursplot->plotting_rect.x)
9498       x=contoursplot->plotting_rect.x;
9499 
9500     if(x > (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width))
9501       x=(contoursplot->plotting_rect.x + contoursplot->plotting_rect.width);
9502 
9503     if (y < contoursplot->plotting_rect.y)
9504       y=contoursplot->plotting_rect.y;
9505 
9506     if (y > (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height))
9507       y=(contoursplot->plotting_rect.y + contoursplot->plotting_rect.height);
9508 
9509     if (contoursplot->zoom_point.x < x){
9510       contoursplot->zoom_rect.x=contoursplot->zoom_point.x;
9511       contoursplot->zoom_rect.width=x-contoursplot->zoom_point.x;
9512     }else{
9513       contoursplot->zoom_rect.x=x;
9514       contoursplot->zoom_rect.width=contoursplot->zoom_point.x-x;
9515     }
9516 
9517     if (contoursplot->zoom_point.y < y){
9518       contoursplot->zoom_rect.y=contoursplot->zoom_point.y;
9519       contoursplot->zoom_rect.height=y-contoursplot->zoom_point.y;
9520     }else{
9521       contoursplot->zoom_rect.y=y;
9522       contoursplot->zoom_rect.height=contoursplot->zoom_point.y-y;
9523     }
9524 
9525     gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9526   }
9527 /* distance between 2 points */
9528   if (contoursplot->mouse_distance_enabled &&
9529       (contoursplot->mouse_button == contoursplot->mouse_distance_button) ){
9530     if (x < contoursplot->plotting_rect.x)
9531       x=contoursplot->plotting_rect.x;
9532 
9533     if(x > (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width))
9534       x=(contoursplot->plotting_rect.x + contoursplot->plotting_rect.width);
9535 
9536     if (y < contoursplot->plotting_rect.y)
9537       y=contoursplot->plotting_rect.y;
9538 
9539     if (y > (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height))
9540       y=(contoursplot->plotting_rect.y + contoursplot->plotting_rect.height);
9541 
9542       contoursplot->distance_rect.x=contoursplot->distance_point.x;
9543       contoursplot->distance_rect.width=x-contoursplot->distance_point.x;
9544 
9545       contoursplot->distance_rect.y=contoursplot->distance_point.y;
9546       contoursplot->distance_rect.height=y-contoursplot->distance_point.y;
9547 
9548     gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9549   }
9550 
9551   if (contoursplot->mouse_displace_enabled && (contoursplot->mouse_button==contoursplot->mouse_displace_button))
9552     if ( (x > contoursplot->plotting_rect.x) &&
9553          (x < (contoursplot->plotting_rect.width + contoursplot->plotting_rect.x)) &&
9554          (y > contoursplot->plotting_rect.y) &&
9555          (y < (contoursplot->plotting_rect.height + contoursplot->plotting_rect.y)) ){
9556       pixel2value(contoursplot, contoursplot->move_point.x, contoursplot->move_point.y, &px, &py);
9557       pixel2value(contoursplot, x, y, &mx, &my);
9558 
9559       gabedit_contoursplot_set_range(contoursplot, contoursplot->xmin+(px-mx), contoursplot->xmax+(px-mx), contoursplot->ymin-(py-my), contoursplot->ymax-(py-my));
9560       contoursplot->move_point.x=x;
9561       contoursplot->move_point.y=y;
9562   }
9563 
9564   return FALSE;
9565 }
9566 /****************************************************************************************/
gabedit_contoursplot_scroll(GtkWidget * widget,GdkEventScroll * event)9567 static gint gabedit_contoursplot_scroll (GtkWidget *widget, GdkEventScroll   *event)
9568 {
9569   GabeditContoursPlot *contoursplot;
9570   gdouble x_range = 0.0, y_range = 0.0,
9571           xmin = 0.0, xmax = 0.0,
9572           ymin = 0.0, ymax = 0.0;
9573 
9574   g_return_val_if_fail (widget != NULL, FALSE);
9575   g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (widget), FALSE);
9576   g_return_val_if_fail (event != NULL, FALSE);
9577 
9578   contoursplot=GABEDIT_ContoursPLOT(widget);
9579 
9580   if (contoursplot->wheel_zoom_enabled){
9581     if (event->direction==GDK_SCROLL_UP){
9582       x_range=contoursplot->wheel_zoom_factor*(contoursplot->xmax-contoursplot->xmin);
9583       y_range=contoursplot->wheel_zoom_factor*(contoursplot->ymax-contoursplot->ymin);
9584     }
9585 
9586     if (event->direction==GDK_SCROLL_DOWN){
9587       x_range=(contoursplot->xmax-contoursplot->xmin)/contoursplot->wheel_zoom_factor;
9588       y_range=(contoursplot->ymax-contoursplot->ymin)/contoursplot->wheel_zoom_factor;
9589     }
9590 
9591     xmin=contoursplot->xmin+((contoursplot->xmax-contoursplot->xmin)/2.0)-(x_range/2.0);
9592     xmax=contoursplot->xmin+((contoursplot->xmax-contoursplot->xmin)/2.0)+(x_range/2.0);
9593 
9594     ymin=contoursplot->ymin+((contoursplot->ymax-contoursplot->ymin)/2.0)-(y_range/2.0);
9595     ymax=contoursplot->ymin+((contoursplot->ymax-contoursplot->ymin)/2.0)+(y_range/2.0);
9596 
9597     gabedit_contoursplot_set_range(contoursplot, xmin, xmax, ymin, ymax);
9598   }
9599   return TRUE;
9600 }
9601 /****************************************************************************************/
gabedit_contoursplot_style_set(GtkWidget * widget,GtkStyle * previous_style)9602 static void gabedit_contoursplot_style_set (GtkWidget *widget, GtkStyle *previous_style)
9603 {
9604   GabeditContoursPlot *contoursplot;
9605 
9606   g_return_if_fail (widget != NULL);
9607   g_return_if_fail (GABEDIT_IS_ContoursPLOT (widget));
9608 
9609   contoursplot = GABEDIT_ContoursPLOT (widget);
9610 
9611   contoursplot_calculate_legends_sizes(contoursplot);
9612   contoursplot_calculate_sizes(contoursplot);
9613   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9614 }
9615 /****************************************************************************************/
gabedit_contoursplot_set_range(GabeditContoursPlot * contoursplot,gdouble xmin,gdouble xmax,gdouble ymin,gdouble ymax)9616 void gabedit_contoursplot_set_range (GabeditContoursPlot *contoursplot, gdouble xmin, gdouble xmax, gdouble ymin, gdouble ymax)
9617 {
9618   g_return_if_fail (contoursplot != NULL);
9619   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9620 
9621   if (xmin < xmax){
9622     contoursplot->xmin=xmin;
9623     contoursplot->xmax=xmax;
9624   }
9625 
9626   if (ymin < ymax){
9627     contoursplot->ymin=ymin;
9628     contoursplot->ymax=ymax;
9629   }
9630 
9631   contoursplot_free_legends(contoursplot);
9632   contoursplot_build_legends(contoursplot);
9633   contoursplot_calculate_sizes(contoursplot);
9634   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9635 }
9636 /****************************************************************************************/
gabedit_contoursplot_set_range_xmin(GabeditContoursPlot * contoursplot,gdouble xmin)9637 void gabedit_contoursplot_set_range_xmin (GabeditContoursPlot *contoursplot, gdouble xmin)
9638 {
9639 	gabedit_contoursplot_set_range(contoursplot, xmin,  contoursplot->xmax, contoursplot->ymin , contoursplot->ymax);
9640 }
9641 /****************************************************************************************/
gabedit_contoursplot_set_range_xmax(GabeditContoursPlot * contoursplot,gdouble xmax)9642 void gabedit_contoursplot_set_range_xmax (GabeditContoursPlot *contoursplot, gdouble xmax)
9643 {
9644 	gabedit_contoursplot_set_range(contoursplot, contoursplot->xmin,  xmax, contoursplot->ymin , contoursplot->ymax);
9645 }
9646 /****************************************************************************************/
gabedit_contoursplot_set_range_ymin(GabeditContoursPlot * contoursplot,gdouble ymin)9647 void gabedit_contoursplot_set_range_ymin (GabeditContoursPlot *contoursplot, gdouble ymin)
9648 {
9649 	gabedit_contoursplot_set_range(contoursplot, contoursplot->xmin,  contoursplot->xmax, ymin , contoursplot->ymax);
9650 }
9651 /****************************************************************************************/
gabedit_contoursplot_set_range_ymax(GabeditContoursPlot * contoursplot,gdouble ymax)9652 void gabedit_contoursplot_set_range_ymax (GabeditContoursPlot *contoursplot, gdouble ymax)
9653 {
9654 	gabedit_contoursplot_set_range(contoursplot, contoursplot->xmin,  contoursplot->xmax, contoursplot->ymin , ymax);
9655 }
9656 /****************************************************************************************/
gabedit_contoursplot_set_autorange(GabeditContoursPlot * contoursplot,ContoursPlotData * data)9657 void gabedit_contoursplot_set_autorange (GabeditContoursPlot *contoursplot, ContoursPlotData *data)
9658 {
9659   gdouble xmax, xmin, ymax, ymin;
9660   ContoursPlotData *current_data;
9661   GList *current_node;
9662 
9663   g_return_if_fail (contoursplot != NULL);
9664   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9665 
9666   xmax=1.0;
9667   xmin=-1.0;
9668   ymax=1.0;
9669   ymin=-1.0;
9670 
9671   if (data!=NULL){
9672     xmax=data->xmax;
9673     xmin=data->xmin;
9674     ymax=data->ymin;
9675     ymin=data->ymax;
9676   }
9677 
9678   if ( (data == NULL) && contoursplot->data_list ){
9679     current_node=g_list_first(contoursplot->data_list);
9680     current_data=(ContoursPlotData*)current_node->data;
9681     xmin=current_data->xmin;
9682     xmax=current_data->xmax;
9683     ymin=current_data->ymin;
9684     ymax=current_data->ymax;
9685     for (; current_node!=NULL; current_node=current_node->next)
9686     {
9687         current_data=(ContoursPlotData*)current_node->data;
9688         if (xmin > current_data->xmin) xmin=current_data->xmin;
9689         if (xmax < current_data->xmax) xmax=current_data->xmax;
9690         if (ymin > current_data->ymin) ymin=current_data->ymin;
9691         if (ymax < current_data->ymax) ymax=current_data->ymax;
9692       }
9693     }
9694 
9695   /*
9696   {
9697   gdouble dx,dy;
9698   dx=fabs(xmax-xmin);
9699   dy=fabs(ymax-ymin);
9700   xmin=xmin-dx*0.1;
9701   xmax=xmax+dx*0.1;
9702   ymin=ymin-dy*0.1;
9703   ymax=ymax+dy*0.1;
9704   }
9705   */
9706 
9707   contoursplot->xmin=xmin;
9708   contoursplot->xmax=xmax;
9709   contoursplot->ymin=ymin;
9710   contoursplot->ymax=ymax;
9711 
9712   contoursplot_free_legends(contoursplot);
9713   contoursplot_build_legends(contoursplot);
9714   contoursplot_calculate_sizes(contoursplot);
9715 
9716   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9717 }
9718 /****************************************************************************************/
gabedit_contoursplot_get_range(GabeditContoursPlot * contoursplot,gdouble * xmin,gdouble * xmax,gdouble * ymin,gdouble * ymax)9719 void gabedit_contoursplot_get_range (GabeditContoursPlot *contoursplot, gdouble *xmin, gdouble *xmax, gdouble *ymin, gdouble *ymax)
9720 {
9721   g_return_if_fail (contoursplot != NULL);
9722   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9723 
9724   if (xmin!=NULL)
9725     *xmin=contoursplot->xmin;
9726   if (xmax!=NULL)
9727     *xmax=contoursplot->xmax;
9728   if (ymax!=NULL)
9729     *ymax=contoursplot->ymax;
9730   if (ymin!=NULL)
9731     *ymin=contoursplot->ymin;
9732 }
9733 /****************************************************************************************/
gabedit_contoursplot_get_point(GabeditContoursPlot * contoursplot,gint x,gint y,gdouble * xv,gdouble * yv)9734 gboolean gabedit_contoursplot_get_point (GabeditContoursPlot *contoursplot, gint x, gint y, gdouble *xv, gdouble *yv)
9735 {
9736   g_return_val_if_fail (contoursplot != NULL, FALSE);
9737   g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot),FALSE);
9738 
9739   /*
9740   if ((x < contoursplot->plotting_rect.x) ||
9741       (x > (contoursplot->plotting_rect.x + contoursplot->plotting_rect.width)) ||
9742       (y < contoursplot->plotting_rect.y) ||
9743       (y > (contoursplot->plotting_rect.y + contoursplot->plotting_rect.height))) {
9744     *xv=*yv=0;
9745     return FALSE;
9746   }
9747   */
9748 
9749   x=x-contoursplot->plotting_rect.x;
9750   y=contoursplot->plotting_rect.y+contoursplot->plotting_rect.height-y;
9751 
9752   pixel2value(contoursplot, x, y, xv, yv);
9753   return TRUE;
9754 }
9755 /****************************************************************************************/
gabedit_contoursplot_get_point_control(GabeditContoursPlot * contoursplot,gint x,gint y,gint width,gint height,gdouble angle,gdouble * xv,gdouble * yv)9756 gboolean gabedit_contoursplot_get_point_control(GabeditContoursPlot *contoursplot, gint x, gint y, gint width, gint height, gdouble angle, gdouble *xv, gdouble *yv )
9757 {
9758 	gdouble xa, ya;
9759 	gdouble xmin,xmax,ymin,ymax;
9760 	gint a[4],b[4];
9761 	gint i;
9762 	gint ixmin,ixmax,iymin,iymax;
9763 	gdouble alpha = angle;
9764 	gdouble l;
9765 	gint lcos;
9766 	gint lsin;
9767 	gint wcos;
9768 	gint wsin;
9769 	gint hcos;
9770 	gint hsin;
9771 	GtkWidget *widget = GTK_WIDGET(contoursplot);
9772 
9773 
9774 	g_return_val_if_fail (contoursplot != NULL, FALSE);
9775 	g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot),FALSE);
9776 	if(width>0) alpha -= atan((gdouble)height/width);
9777 	l = sqrt(width*width+height*height);
9778 	lcos = (gint)(l*cos(alpha));
9779 	lsin = (gint)(l*sin(alpha));
9780 	wcos = (gint)(width*cos(angle));
9781 	wsin = (gint)(width*sin(angle));
9782 	hcos = (gint)(height*cos(angle-M_PI/2));
9783 	hsin = (gint)(height*sin(angle-M_PI/2));
9784 
9785 	ixmin = 0;
9786 	if(ixmin<-lcos) ixmin = -lcos;
9787 	if(ixmin<-wcos) ixmin = -wcos;
9788 	if(ixmin<-hcos) ixmin = -hcos;
9789 
9790 	iymin = 0;
9791 	if(iymin<lsin) iymin = lsin;
9792 	if(iymin<wsin) iymin = wsin;
9793 	if(iymin<hsin) iymin = hsin;
9794 
9795 	ixmax = 0;
9796 	if(ixmax<lcos) ixmax = lcos;
9797 	if(ixmax<wcos) ixmax = wcos;
9798 	if(ixmax<hcos) ixmax = hcos;
9799 	ixmax = widget->allocation.width-ixmax;
9800 
9801 	iymax = 0;
9802 	if(iymax<-lsin) iymax = -lsin;
9803 	if(iymax<-wsin) iymax = -wsin;
9804 	if(iymax<-hsin) iymax = -hsin;
9805 	iymax = widget->allocation.height-iymax;
9806 
9807 	/* printf("iminmax = %d %d %d %d\n",ixmin,ixmax,iymin,iymax);*/
9808 	a[0] = ixmin;
9809 	a[1] = ixmax;
9810 	a[2] = ixmax;
9811 	a[3] = ixmin;
9812 	b[0] = iymin;
9813 	b[1] = iymin;
9814 	b[2] = iymax;
9815 	b[3] = iymax;
9816 
9817 	gabedit_contoursplot_get_point (contoursplot, x, y, xv, yv);
9818 	xmin = xmax = *xv;
9819 	ymin = ymax = *yv;
9820 	for(i=0;i<4;i++)
9821 	{
9822 		gabedit_contoursplot_get_point (contoursplot, a[i], b[i], &xa, &ya);
9823 		if(i==0)
9824 		{
9825 			xmin = xa;
9826 			xmax = xa;
9827 			ymin = ya;
9828 			ymax = ya;
9829 		}
9830 		else
9831 		{
9832 			if(xmin>xa) xmin = xa;
9833 			if(ymin>ya) ymin = ya;
9834 			if(xmax<xa) xmax = xa;
9835 			if(ymax<ya) ymax = ya;
9836 		}
9837 	}
9838 	/* printf("xmax ymax = %f %f\n",xmax,ymax);*/
9839 
9840 	if(*xv<xmin) *xv = xmin;
9841 	if(*yv<ymin) *yv = ymin;
9842 	if(*xv>xmax) *xv = xmax;
9843 	if(*yv>ymax) *yv = ymax;
9844 	return TRUE;
9845 }
9846 /****************************************************************************************/
gabedit_contoursplot_set_ticks(GabeditContoursPlot * contoursplot,gint hmajor,gint hminor,gint vmajor,gint vminor,gint length)9847 void gabedit_contoursplot_set_ticks (GabeditContoursPlot *contoursplot, gint hmajor, gint hminor, gint vmajor, gint vminor, gint length)
9848 {
9849   g_return_if_fail (contoursplot != NULL);
9850   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9851 
9852   contoursplot_free_legends(contoursplot);
9853 
9854   contoursplot->hmajor_ticks=hmajor;
9855   contoursplot->hminor_ticks=hminor;
9856   contoursplot->vmajor_ticks=vmajor;
9857   contoursplot->vminor_ticks=vminor;
9858   contoursplot->length_ticks=length;
9859 
9860   contoursplot_build_legends(contoursplot);
9861   contoursplot_calculate_sizes(contoursplot);
9862   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9863 }
9864 /****************************************************************************************/
gabedit_contoursplot_set_ticks_hmajor(GabeditContoursPlot * contoursplot,gint hmajor)9865 void gabedit_contoursplot_set_ticks_hmajor (GabeditContoursPlot *contoursplot, gint hmajor)
9866 {
9867   g_return_if_fail (contoursplot != NULL);
9868   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9869 
9870   contoursplot_free_legends(contoursplot);
9871 
9872   contoursplot->hmajor_ticks=hmajor;
9873 
9874   contoursplot_build_legends(contoursplot);
9875   contoursplot_calculate_sizes(contoursplot);
9876   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9877 }
9878 /****************************************************************************************/
gabedit_contoursplot_set_ticks_hminor(GabeditContoursPlot * contoursplot,gint hminor)9879 void gabedit_contoursplot_set_ticks_hminor (GabeditContoursPlot *contoursplot, gint hminor)
9880 {
9881   g_return_if_fail (contoursplot != NULL);
9882   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9883 
9884   contoursplot_free_legends(contoursplot);
9885 
9886   contoursplot->hminor_ticks=hminor;
9887 
9888   contoursplot_build_legends(contoursplot);
9889   contoursplot_calculate_sizes(contoursplot);
9890   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9891 }
9892 /****************************************************************************************/
gabedit_contoursplot_set_ticks_vmajor(GabeditContoursPlot * contoursplot,gint vmajor)9893 void gabedit_contoursplot_set_ticks_vmajor (GabeditContoursPlot *contoursplot, gint vmajor)
9894 {
9895   g_return_if_fail (contoursplot != NULL);
9896   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9897 
9898   contoursplot_free_legends(contoursplot);
9899 
9900   contoursplot->vmajor_ticks=vmajor;
9901 
9902   contoursplot_build_legends(contoursplot);
9903   contoursplot_calculate_sizes(contoursplot);
9904   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9905 }
9906 /****************************************************************************************/
gabedit_contoursplot_set_ticks_vminor(GabeditContoursPlot * contoursplot,gint vminor)9907 void gabedit_contoursplot_set_ticks_vminor (GabeditContoursPlot *contoursplot, gint vminor)
9908 {
9909   g_return_if_fail (contoursplot != NULL);
9910   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9911 
9912   contoursplot_free_legends(contoursplot);
9913 
9914   contoursplot->vminor_ticks=vminor;
9915 
9916   contoursplot_build_legends(contoursplot);
9917   contoursplot_calculate_sizes(contoursplot);
9918   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9919 }
9920 /****************************************************************************************/
gabedit_contoursplot_set_ticks_length(GabeditContoursPlot * contoursplot,gint length)9921 void gabedit_contoursplot_set_ticks_length (GabeditContoursPlot *contoursplot, gint length)
9922 {
9923   g_return_if_fail (contoursplot != NULL);
9924   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9925 
9926   contoursplot_free_legends(contoursplot);
9927 
9928   contoursplot->length_ticks=length;
9929 
9930   contoursplot_build_legends(contoursplot);
9931   contoursplot_calculate_sizes(contoursplot);
9932   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9933 }
9934 /****************************************************************************************/
gabedit_contoursplot_get_ticks(GabeditContoursPlot * contoursplot,gint * hmajor,gint * hminor,gint * vmajor,gint * vminor,gint * length)9935 void gabedit_contoursplot_get_ticks (GabeditContoursPlot *contoursplot, gint *hmajor, gint *hminor, gint *vmajor, gint *vminor, gint* length)
9936 {
9937   g_return_if_fail (contoursplot != NULL);
9938   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9939 
9940   if (hmajor!=NULL)
9941     *hmajor=contoursplot->hmajor_ticks;
9942   if (hminor!=NULL)
9943     *hminor=contoursplot->hminor_ticks;
9944   if (vmajor!=NULL)
9945     *vmajor=contoursplot->vmajor_ticks;
9946   if (vminor!=NULL)
9947     *vminor=contoursplot->vminor_ticks;
9948   if (length!=NULL)
9949     *length=contoursplot->length_ticks;
9950 }
9951 /****************************************************************************************/
gabedit_contoursplot_set_margins_left(GabeditContoursPlot * contoursplot,gint left)9952 void gabedit_contoursplot_set_margins_left (GabeditContoursPlot *contoursplot, gint left)
9953 {
9954   g_return_if_fail (contoursplot != NULL);
9955   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9956 
9957   contoursplot_free_legends(contoursplot);
9958 
9959   contoursplot->left_margins=left;
9960 
9961   contoursplot_build_legends(contoursplot);
9962   contoursplot_calculate_sizes(contoursplot);
9963   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9964 }
9965 /****************************************************************************************/
gabedit_contoursplot_set_margins_right(GabeditContoursPlot * contoursplot,gint right)9966 void gabedit_contoursplot_set_margins_right (GabeditContoursPlot *contoursplot, gint right)
9967 {
9968   g_return_if_fail (contoursplot != NULL);
9969   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9970 
9971   contoursplot_free_legends(contoursplot);
9972 
9973   contoursplot->right_margins=right;
9974 
9975   contoursplot_build_legends(contoursplot);
9976   contoursplot_calculate_sizes(contoursplot);
9977   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9978 }
9979 /****************************************************************************************/
gabedit_contoursplot_set_margins_top(GabeditContoursPlot * contoursplot,gint top)9980 void gabedit_contoursplot_set_margins_top (GabeditContoursPlot *contoursplot, gint top)
9981 {
9982   g_return_if_fail (contoursplot != NULL);
9983   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9984 
9985   contoursplot_free_legends(contoursplot);
9986 
9987   contoursplot->top_margins=top;
9988 
9989   contoursplot_build_legends(contoursplot);
9990   contoursplot_calculate_sizes(contoursplot);
9991   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
9992 }
9993 /****************************************************************************************/
gabedit_contoursplot_set_margins_bottom(GabeditContoursPlot * contoursplot,gint bottom)9994 void gabedit_contoursplot_set_margins_bottom (GabeditContoursPlot *contoursplot, gint bottom)
9995 {
9996   g_return_if_fail (contoursplot != NULL);
9997   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
9998 
9999   contoursplot_free_legends(contoursplot);
10000 
10001   contoursplot->bottom_margins=bottom;
10002 
10003   contoursplot_build_legends(contoursplot);
10004   contoursplot_calculate_sizes(contoursplot);
10005   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10006 }
10007 /****************************************************************************************/
gabedit_contoursplot_set_x_legends_digits(GabeditContoursPlot * contoursplot,gint digits)10008 void gabedit_contoursplot_set_x_legends_digits (GabeditContoursPlot *contoursplot, gint digits)
10009 {
10010   g_return_if_fail (contoursplot != NULL);
10011   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10012 
10013   if (digits != contoursplot->x_legends_digits){
10014     contoursplot_free_legends(contoursplot);
10015 
10016     contoursplot->x_legends_digits=digits;
10017 
10018     contoursplot_build_legends(contoursplot);
10019     contoursplot_calculate_legends_sizes(contoursplot);
10020     contoursplot_calculate_sizes(contoursplot);
10021     gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10022   }
10023 }
10024 /****************************************************************************************/
gabedit_contoursplot_set_y_legends_digits(GabeditContoursPlot * contoursplot,gint digits)10025 void gabedit_contoursplot_set_y_legends_digits (GabeditContoursPlot *contoursplot, gint digits)
10026 {
10027   g_return_if_fail (contoursplot != NULL);
10028   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10029 
10030   if (digits != contoursplot->y_legends_digits){
10031     contoursplot_free_legends(contoursplot);
10032 
10033     contoursplot->y_legends_digits=digits;
10034 
10035     contoursplot_build_legends(contoursplot);
10036     contoursplot_calculate_legends_sizes(contoursplot);
10037     contoursplot_calculate_sizes(contoursplot);
10038     gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10039   }
10040 }
10041 /****************************************************************************************/
gabedit_contoursplot_get_x_legends_digits(GabeditContoursPlot * contoursplot)10042 gint gabedit_contoursplot_get_x_legends_digits (GabeditContoursPlot *contoursplot)
10043 {
10044   g_return_val_if_fail (contoursplot != NULL, 0);
10045   g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot), 0);
10046 
10047   return(contoursplot->x_legends_digits);
10048 }
10049 /****************************************************************************************/
gabedit_contoursplot_get_y_legends_digits(GabeditContoursPlot * contoursplot)10050 gint gabedit_contoursplot_get_y_legends_digits (GabeditContoursPlot *contoursplot)
10051 {
10052   g_return_val_if_fail (contoursplot != NULL, 0);
10053   g_return_val_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot), 0);
10054 
10055   return(contoursplot->y_legends_digits);
10056 }
10057 /****************************************************************************************/
gabedit_contoursplot_set_background_color(GabeditContoursPlot * contoursplot,GdkColor color)10058 void gabedit_contoursplot_set_background_color (GabeditContoursPlot *contoursplot, GdkColor color)
10059 {
10060   g_return_if_fail (contoursplot != NULL);
10061   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10062 
10063   gdk_gc_set_rgb_fg_color(contoursplot->back_gc, &color);
10064 
10065   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10066 }
10067 /****************************************************************************************/
gabedit_contoursplot_set_grids_attributes(GabeditContoursPlot * contoursplot,GabeditContoursPlotGrid grid,GdkColor color,gint line_width,GdkLineStyle line_style)10068 void gabedit_contoursplot_set_grids_attributes (GabeditContoursPlot *contoursplot,
10069 			GabeditContoursPlotGrid grid,
10070 			GdkColor color,
10071 			gint line_width,
10072 			GdkLineStyle line_style)
10073 {
10074   GdkGC *gc;
10075 
10076   g_return_if_fail (contoursplot != NULL);
10077   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10078 
10079   switch (grid){
10080     case GABEDIT_ContoursPLOT_HMAJOR_GRID:
10081       gc=contoursplot->hmajor_grid_gc;
10082     break;
10083     case GABEDIT_ContoursPLOT_HMINOR_GRID:
10084       gc=contoursplot->hminor_grid_gc;
10085     break;
10086     case GABEDIT_ContoursPLOT_VMAJOR_GRID:
10087       gc=contoursplot->vmajor_grid_gc;
10088     break;
10089     case GABEDIT_ContoursPLOT_VMINOR_GRID:
10090       gc=contoursplot->vminor_grid_gc;
10091     break;
10092     default:
10093       return;
10094   }
10095 
10096   gdk_gc_set_rgb_fg_color(gc, &color);
10097   gdk_gc_set_line_attributes(gc, line_width, line_style, 0 ,0);
10098 
10099   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10100 }
10101 /****************************************************************************************/
gabedit_contoursplot_get_grids_attributes(GabeditContoursPlot * contoursplot,GabeditContoursPlotGrid grid,GdkColor * color,gint * line_width,GdkLineStyle * line_style)10102 void gabedit_contoursplot_get_grids_attributes (GabeditContoursPlot *contoursplot,
10103 			GabeditContoursPlotGrid grid,
10104 			GdkColor *color,
10105 			gint *line_width,
10106 			GdkLineStyle *line_style)
10107 {
10108   GdkGC *gc;
10109   GdkGCValues gc_values;
10110 
10111   g_return_if_fail (contoursplot != NULL);
10112   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10113   g_return_if_fail (color != NULL);
10114   g_return_if_fail (line_width != NULL);
10115   g_return_if_fail (line_style != NULL);
10116 
10117   switch (grid){
10118     case GABEDIT_ContoursPLOT_HMAJOR_GRID:
10119       gc=contoursplot->hmajor_grid_gc;
10120     break;
10121     case GABEDIT_ContoursPLOT_HMINOR_GRID:
10122       gc=contoursplot->hminor_grid_gc;
10123     break;
10124     case GABEDIT_ContoursPLOT_VMAJOR_GRID:
10125       gc=contoursplot->vmajor_grid_gc;
10126     break;
10127     case GABEDIT_ContoursPLOT_VMINOR_GRID:
10128       gc=contoursplot->vminor_grid_gc;
10129     break;
10130     default:
10131       return;
10132   }
10133 
10134   gdk_gc_get_values(gc, &gc_values);
10135 
10136   *color=gc_values.foreground;
10137   *line_width=gc_values.line_width;
10138   *line_style=gc_values.line_style;
10139 }
10140 /****************************************************************************************/
contoursplot_enable_grids(GabeditContoursPlot * contoursplot,GabeditContoursPlotGrid grid,gboolean enable)10141 static void contoursplot_enable_grids (GabeditContoursPlot *contoursplot, GabeditContoursPlotGrid grid, gboolean enable)
10142 {
10143   g_return_if_fail (contoursplot != NULL);
10144   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10145 
10146   switch (grid){
10147     case GABEDIT_ContoursPLOT_HMAJOR_GRID:
10148       contoursplot->hmajor_grid=enable;
10149     break;
10150     case GABEDIT_ContoursPLOT_HMINOR_GRID:
10151       contoursplot->hminor_grid=enable;
10152     break;
10153     case GABEDIT_ContoursPLOT_VMAJOR_GRID:
10154       contoursplot->vmajor_grid=enable;
10155     break;
10156     case GABEDIT_ContoursPLOT_VMINOR_GRID:
10157       contoursplot->vminor_grid=enable;
10158     break;
10159     default:
10160       return;
10161   }
10162 
10163   contoursplot_calculate_sizes(contoursplot);
10164   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10165 }
10166 /****************************************************************************************/
gabedit_contoursplot_enable_grids(GabeditContoursPlot * contoursplot,GabeditContoursPlotGrid grid,gboolean enable)10167 void gabedit_contoursplot_enable_grids (GabeditContoursPlot *contoursplot, GabeditContoursPlotGrid grid, gboolean enable)
10168 {
10169 
10170 	GtkUIManager *manager = g_object_get_data(G_OBJECT (contoursplot), "Manager");
10171 	GtkAction* action = NULL;
10172 	if(grid==GABEDIT_ContoursPLOT_HMAJOR_GRID)
10173 		action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderGrid/HGridShowMajor");
10174 	if(grid==GABEDIT_ContoursPLOT_HMINOR_GRID)
10175 		action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderGrid/HGridShowMinor");
10176 	if(grid==GABEDIT_ContoursPLOT_VMAJOR_GRID)
10177 		action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderGrid/VGridShowMajor");
10178 	if(grid==GABEDIT_ContoursPLOT_VMINOR_GRID)
10179 		action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderGrid/VGridShowMinor");
10180 	if(action) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),enable);
10181 }
10182 /****************************************************************************************/
gabedit_contoursplot_add_data(GabeditContoursPlot * contoursplot,ContoursPlotData * data)10183 void gabedit_contoursplot_add_data(GabeditContoursPlot *contoursplot, ContoursPlotData *data)
10184 {
10185 	g_return_if_fail (contoursplot != NULL);
10186 	g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10187 	g_return_if_fail (data != NULL);
10188 
10189 	if (g_list_find (contoursplot->data_list, (gpointer)data)==NULL)
10190 	{
10191 		gint i;
10192 		contoursplot->data_list=g_list_append(contoursplot->data_list, (gpointer) data);
10193 		for(i=0;i<data->nContours;i++)
10194 		contoursplot_build_points_contour(GABEDIT_ContoursPLOT(contoursplot), &data->contours[i]);
10195 	}
10196 }
10197 /****************************************************************************************/
gabedit_contoursplot_remove_data(GabeditContoursPlot * contoursplot,ContoursPlotData * data)10198 void gabedit_contoursplot_remove_data(GabeditContoursPlot *contoursplot, ContoursPlotData *data)
10199 {
10200   g_return_if_fail (contoursplot != NULL);
10201   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10202   g_return_if_fail (data != NULL);
10203 
10204   if (g_list_find (contoursplot->data_list, (gpointer)data)!=NULL){
10205     contoursplot->data_list=g_list_remove_all (contoursplot->data_list, (gpointer) data);
10206   }
10207 }
10208 
10209 /****************************************************************************************/
gabedit_contoursplot_configure_mouse_zoom(GabeditContoursPlot * contoursplot,gboolean enabled,gint button)10210 void gabedit_contoursplot_configure_mouse_zoom(GabeditContoursPlot *contoursplot, gboolean enabled, gint button)
10211 {
10212   g_return_if_fail (contoursplot != NULL);
10213   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10214 
10215   contoursplot->mouse_zoom_enabled=enabled;
10216   contoursplot->mouse_zoom_button=button;
10217 }
10218 /****************************************************************************************/
gabedit_contoursplot_configure_mouse_distance(GabeditContoursPlot * contoursplot,gboolean enabled,gint button)10219 void gabedit_contoursplot_configure_mouse_distance(GabeditContoursPlot *contoursplot, gboolean enabled, gint button)
10220 {
10221   g_return_if_fail (contoursplot != NULL);
10222   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10223 
10224   contoursplot->mouse_distance_enabled=enabled;
10225   contoursplot->mouse_distance_button=button;
10226 }
10227 /****************************************************************************************/
gabedit_contoursplot_configure_wheel_zoom(GabeditContoursPlot * contoursplot,gboolean enabled,gdouble factor)10228 void gabedit_contoursplot_configure_wheel_zoom(GabeditContoursPlot *contoursplot, gboolean enabled, gdouble factor)
10229 {
10230   g_return_if_fail (contoursplot != NULL);
10231   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10232 
10233   contoursplot->wheel_zoom_enabled=enabled;
10234   contoursplot->wheel_zoom_factor=factor;
10235 }
10236 /****************************************************************************************/
gabedit_contoursplot_configure_mouse_displace(GabeditContoursPlot * contoursplot,gboolean enabled,gint button)10237 void gabedit_contoursplot_configure_mouse_displace(GabeditContoursPlot *contoursplot, gboolean enabled, gint button)
10238 {
10239   g_return_if_fail (contoursplot != NULL);
10240   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10241 
10242   contoursplot->mouse_displace_enabled=enabled;
10243   contoursplot->mouse_displace_button=button;
10244 }
10245 /****************************************************************************************/
gabedit_contoursplot_configure_mouse_autorange(GabeditContoursPlot * contoursplot,gboolean enabled,gint button)10246 void gabedit_contoursplot_configure_mouse_autorange(GabeditContoursPlot *contoursplot, gboolean enabled, gint button)
10247 {
10248   g_return_if_fail (contoursplot != NULL);
10249   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10250 
10251   contoursplot->mouse_autorange_enabled=enabled;
10252   contoursplot->mouse_autorange_button=button;
10253 }
10254 /********************************************************************************/
get_rgb_image(GtkWidget * drawable)10255 static guchar *get_rgb_image(GtkWidget* drawable)
10256 {
10257 	gdouble fac=255.0/65535.0;
10258 	GdkColormap *colormap;
10259   	gint height;
10260   	gint width;
10261 	gint32 pixel;
10262   	GdkImage* image = NULL;
10263 	GdkVisual *v;
10264 	gint8 component;
10265 	gint k=0;
10266 	gint x;
10267 	gint y;
10268 	gint i;
10269 	guchar* rgbbuf=NULL;
10270 
10271 
10272 	colormap = gdk_window_get_colormap(GTK_WIDGET(drawable)->window);
10273   	height = drawable->allocation.height;
10274   	width = drawable->allocation.width;
10275 	rgbbuf=(guchar *) g_malloc(3*width*height*sizeof(guchar));
10276 
10277   	if(!colormap) return NULL;
10278 	if(!rgbbuf) return NULL;
10279 
10280 	image = gdk_image_get(drawable->window,0,0,width,height);
10281 
10282 	v = gdk_colormap_get_visual(colormap);
10283 
10284 	switch(v->type)
10285 	{
10286 		case GDK_VISUAL_STATIC_GRAY:
10287 		case GDK_VISUAL_GRAYSCALE:
10288 		case GDK_VISUAL_STATIC_COLOR:
10289 		case GDK_VISUAL_PSEUDO_COLOR:
10290 		for(y=height-1;y>=0;y--)
10291 		for(x=0;x<(gint)width;x++)
10292 		{
10293 			pixel = gdk_image_get_pixel(image, x, y);
10294 			rgbbuf[k] = (guchar)(colormap->colors[pixel].red*fac);
10295 			rgbbuf[k+1] =(guchar) (colormap->colors[pixel].green*fac);
10296 			rgbbuf[k+2] =(guchar) (colormap->colors[pixel].blue*fac);
10297 			k+=3;
10298 		}
10299 		break;
10300 
10301 	    case GDK_VISUAL_TRUE_COLOR:
10302 		for(y=height-1;y>=0;y--)
10303 		for(x=0;x<(gint)width;x++)
10304 		{
10305 			pixel = gdk_image_get_pixel(image, x, y);
10306 	      		component = 0;
10307 	      		for (i = 24; i < 32; i += v->red_prec)
10308 				component |= ((pixel & v->red_mask) << (32 - v->red_shift - v->red_prec)) >> i;
10309 	      		rgbbuf[k] = (guchar)(component);
10310 
10311 			component = 0;
10312 	      		for (i = 24; i < 32; i += v->green_prec)
10313 				component |= ((pixel & v->green_mask) << (32 - v->green_shift - v->green_prec)) >> i;
10314 	      		rgbbuf[k+1] = (guchar)(component);
10315 	      		component = 0;
10316 	      		for (i = 24; i < 32; i += v->blue_prec)
10317 				component |= ((pixel & v->blue_mask) << (32 - v->blue_shift - v->blue_prec)) >> i;
10318 	      		rgbbuf[k+2] = (guchar)(component);
10319 	      		k += 3;
10320 		}
10321 	       break;
10322 	    case GDK_VISUAL_DIRECT_COLOR:
10323 		for(y=height-1;y>=0;y--)
10324 		for(x=0;x<(gint)width;x++)
10325 		{
10326 			pixel = gdk_image_get_pixel(image, x, y);
10327 	      		component = colormap->colors[((pixel & v->red_mask) << (32 - v->red_shift - v->red_prec)) >> 24].red;
10328 	      		rgbbuf[k] = (guchar)(component*fac);
10329 
10330       			component = colormap->colors[((pixel & v->green_mask) << (32 - v->green_shift - v->green_prec)) >> 24].green;
10331       			rgbbuf[k+1] = (guchar)(component*fac);
10332       			component = colormap->colors[((pixel & v->blue_mask) << (32 - v->blue_shift - v->blue_prec)) >> 24].blue;
10333       			rgbbuf[k+2] = (guchar)(component*fac);
10334       			k += 3;
10335 		}
10336 	       break;
10337 	       default :
10338 	       {
10339 		        g_free(rgbbuf);
10340 		      	return NULL;
10341 	       }
10342 	}
10343 	return rgbbuf;
10344 }
10345 /********************************************************************************/
WLSBL(int val,char * arr)10346 static void WLSBL(int val,char* arr)
10347 {
10348     arr[0] = (char) (val&0xff);
10349     arr[1] = (char) ((val>>8) &0xff);
10350     arr[2] = (char) ((val>>16)&0xff);
10351     arr[3] = (char) ((val>>24)&0xff);
10352 }
10353 /**************************************************************************/
writeBMP(GabeditContoursPlot * contoursplot,gchar * fileName)10354 static void writeBMP(GabeditContoursPlot *contoursplot, gchar *fileName)
10355 {
10356   	guchar rgbtmp[3];
10357   	int pad;
10358 	char bmp_header[]=
10359 	{ 'B','M', 0,0,0,0, 0,0, 0,0, 54,0,0,0,
10360   	40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 24,0, 0,0,0,0, 0,0,0,0,
10361   	0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 };
10362 	GtkWidget *drawable;
10363 
10364 	FILE *file;
10365 	int i;
10366 	int j;
10367 	int width;
10368 	int height;
10369 	guchar *rgbbuf;
10370 
10371         file = fopen(fileName,"wb");
10372 
10373         if (!file) return;
10374 
10375 	drawable = GTK_WIDGET(contoursplot);
10376 
10377 	rgbbuf = get_rgb_image(drawable);
10378 	if (!rgbbuf) {
10379 	    	fclose(file);
10380             	return;
10381 	}
10382 	width =  drawable->allocation.width;
10383 	height = drawable->allocation.height;
10384 
10385 
10386 /* The number of bytes on a screenline should be wholly devisible by 4 */
10387 
10388   	pad = (width*3)%4;
10389   	if (pad) pad = 4 - pad;
10390 
10391   	WLSBL((int) (3*width+pad)*height+54,bmp_header+2);
10392   	WLSBL((int) width,bmp_header+18);
10393   	WLSBL((int) height,bmp_header+22);
10394   	WLSBL((int) 3*width*height,bmp_header+34);
10395 
10396   	{int it = fwrite(bmp_header,1,54,file);}
10397 
10398   	for (i=0;i<height;i++)
10399 	{
10400     		for (j=0;j<width;j++)
10401 		{
10402 			rgbtmp[0] = rgbbuf[(j+width*i)*3+2];
10403 			rgbtmp[1] = rgbbuf[(j+width*i)*3+1];
10404 			rgbtmp[2] = rgbbuf[(j+width*i)*3+0];
10405 			{int it = fwrite(rgbtmp,3,1,file);}
10406     		}
10407     	rgbtmp[0] = (char) 0;
10408     	for (j=0;j<pad;j++)
10409 		{ int it = fwrite(rgbtmp,1,1,file);}
10410   	}
10411 
10412   	fclose(file);
10413   	g_free(rgbbuf);
10414 }
10415 /****************************************************************************************/
writeTransparentPNG(GabeditContoursPlot * contoursplot,gchar * fileName)10416 static void writeTransparentPNG(GabeditContoursPlot *contoursplot, gchar *fileName)
10417 {
10418 	GtkWidget* widget = GTK_WIDGET(contoursplot);
10419 	int width;
10420 	int height;
10421 	GError *error = NULL;
10422 	GdkPixbuf  *pixbuf = NULL;
10423 	width =  widget->allocation.width;
10424 	height = widget->allocation.height;
10425 	pixbuf = gdk_pixbuf_get_from_drawable(NULL, widget->window, NULL, 0, 0, 0, 0, width, height);
10426 	if(pixbuf)
10427 	{
10428 		GdkPixbuf  *pixbufNew = NULL;
10429 		guchar color[3] = {255, 255, 255};
10430 		GdkColor c;
10431 		GdkGCValues gc_values;
10432 
10433 		GdkColormap *colormap;
10434    		colormap  = gdk_window_get_colormap(widget->window);
10435 		gdk_gc_get_values(contoursplot->back_gc, &gc_values);
10436         	gdk_colormap_query_color(colormap, gc_values.foreground.pixel,&c);
10437 
10438 		color[0] = (guchar)(SCALE(c.red)*255);
10439 		color[1] = (guchar)(SCALE(c.green)*255);
10440 		color[2] = (guchar)(SCALE(c.blue)*255);
10441 
10442 
10443 		pixbufNew = gdk_pixbuf_add_alpha(pixbuf, TRUE, color[0], color[1], color[2]);
10444 		if(pixbufNew) gdk_pixbuf_save(pixbufNew, fileName, "png", &error, NULL);
10445 		else gdk_pixbuf_save(pixbuf, fileName, "png", &error, NULL);
10446 	 	g_object_unref (pixbuf);
10447 	 	g_object_unref (pixbufNew);
10448 	}
10449 }
10450 /****************************************************************************************/
gabedit_contoursplot_save_image(GabeditContoursPlot * contoursplot,gchar * fileName,gchar * type)10451 void gabedit_contoursplot_save_image(GabeditContoursPlot *contoursplot, gchar *fileName, gchar* type)
10452 {
10453 	GtkWidget* widget = GTK_WIDGET(contoursplot);
10454 	int width;
10455 	int height;
10456 	GError *error = NULL;
10457 	GdkPixbuf  *pixbuf = NULL;
10458 
10459 	if(fileName && type && !strcmp(type,"bmp"))
10460 	{
10461 		writeBMP(contoursplot, fileName);
10462 		return;
10463 	}
10464 	if(fileName && type && !strcmp(type,"tpng"))
10465 	{
10466 		writeTransparentPNG(contoursplot, fileName);
10467 		return;
10468 	}
10469 
10470 	width =  widget->allocation.width;
10471 	height = widget->allocation.height;
10472 	pixbuf = gdk_pixbuf_get_from_drawable(NULL, widget->window, NULL, 0, 0, 0, 0, width, height);
10473 	if(pixbuf)
10474 	{
10475 		if(!fileName)
10476 		{
10477 			GtkClipboard * clipboard;
10478 			clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
10479 			if(clipboard)
10480 			{
10481 				gtk_clipboard_clear(clipboard);
10482 				gtk_clipboard_set_image(clipboard, pixbuf);
10483 			}
10484 		}
10485 		else
10486 		{
10487 			if(type && strstr(type,"j") && strstr(type,"g") )
10488 			gdk_pixbuf_save(pixbuf, fileName, type, &error, "quality", "100", NULL);
10489 			else if(type && strstr(type,"png"))
10490 			gdk_pixbuf_save(pixbuf, fileName, type, &error, "compression", "5", NULL);
10491 			else if(type && (strstr(type,"tif") || strstr(type,"tiff")))
10492 			gdk_pixbuf_save(pixbuf, fileName, "tiff", &error, "compression", "1", NULL);
10493 			else
10494 			gdk_pixbuf_save(pixbuf, fileName, type, &error, NULL);
10495 		}
10496 	 	g_object_unref (pixbuf);
10497 	}
10498 }
10499 /****************************************************************************************/
contoursplot_calculate_sizes(GabeditContoursPlot * contoursplot)10500 static void contoursplot_calculate_sizes (GabeditContoursPlot *contoursplot)
10501 {
10502   GtkWidget *widget;
10503   gint left = 10;
10504   gint right = 10;
10505   gint top = 5;
10506   gint bottom = 5;
10507 
10508   g_return_if_fail (contoursplot != NULL);
10509   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10510 
10511   widget = GTK_WIDGET(contoursplot);
10512   left += 0.75*((gdouble)contoursplot->y_legends_width);
10513   right += 0.75*((gdouble)contoursplot->y_legends_width);
10514   top += 0.5*((gdouble)contoursplot->x_legends_height);
10515   bottom += 0.5*((gdouble)contoursplot->x_legends_height);
10516   if(contoursplot->show_left_legends) left = 10+1.5*((gdouble)contoursplot->y_legends_width)+1.0*((gdouble)contoursplot->v_label_height);
10517   if(contoursplot->show_right_legends) right = 10+1.5*((gdouble)contoursplot->y_legends_width)+1.0*((gdouble)contoursplot->v_label_height);
10518   if(contoursplot->show_top_legends) top = 5+1.5*((gdouble)contoursplot->x_legends_height)+1.0*((gdouble)contoursplot->h_label_height);
10519   if(contoursplot->show_bottom_legends) bottom = 5+1.5*((gdouble)contoursplot->x_legends_height)+1.0*((gdouble)contoursplot->h_label_height);
10520   if(contoursplot->show_colormap) right += (gdouble)contoursplot->colormap_width;
10521   if (contoursplot->v_label && !contoursplot->show_left_legends && contoursplot->show_right_legends) right += contoursplot->v_label_height;
10522 
10523   left += (gint)(contoursplot->left_margins/100.0*widget->allocation.width);
10524   right += (gint)(contoursplot->right_margins/100.0*widget->allocation.width);
10525   top += (gint)(contoursplot->top_margins/100.0*widget->allocation.height);
10526   bottom += (gint)(contoursplot->bottom_margins/100.0*widget->allocation.height);
10527 
10528   contoursplot->plotting_rect.x = left;
10529   contoursplot->plotting_rect.y = top;
10530 
10531 
10532   contoursplot->plotting_rect.width=widget->allocation.width  -left - right;
10533 
10534   contoursplot->plotting_rect.height=widget->allocation.height  - top - bottom ;
10535 
10536   if (contoursplot->hmajor_ticks>1){
10537     contoursplot->d_hmajor=((gdouble)contoursplot->plotting_rect.width)/((gdouble)contoursplot->hmajor_ticks-1.0);
10538     contoursplot->d_hminor=((gdouble)contoursplot->d_hmajor)/((gdouble)contoursplot->hminor_ticks+1.0);
10539   }
10540 
10541   if (contoursplot->vmajor_ticks>1){
10542     contoursplot->d_vmajor=((gdouble)contoursplot->plotting_rect.height)/((gdouble)contoursplot->vmajor_ticks-1.0);
10543     contoursplot->d_vminor=((gdouble)contoursplot->d_vmajor)/((gdouble)contoursplot->vminor_ticks+1.0);
10544   }
10545 
10546   /* Creating the plotting area (everytime the plotting area's size is changed, the size of the pismap
10547      must be changed too, so, a new one, with the right size is created*/
10548   if (contoursplot->plotting_area!=NULL) g_object_unref(G_OBJECT(contoursplot->plotting_area));
10549   if (contoursplot->cairo_widget!=NULL) cairo_destroy (contoursplot->cairo_widget);
10550   if (contoursplot->cairo_area!=NULL) cairo_destroy (contoursplot->cairo_area);
10551 
10552   if (GTK_WIDGET_REALIZED(widget))
10553   {
10554     contoursplot->plotting_area=gdk_pixmap_new(widget->window, contoursplot->plotting_rect.width, contoursplot->plotting_rect.height, -1);
10555     contoursplot->cairo_area = gdk_cairo_create (contoursplot->plotting_area);
10556     contoursplot->cairo_widget = gdk_cairo_create (widget->window);
10557   }
10558   contoursplot->colormap_height = contoursplot->plotting_rect.height;
10559   reset_object_text_pixels(contoursplot);
10560   reset_object_line_pixels(contoursplot);
10561 }
10562 /****************************************************************************************/
value2pixel(GabeditContoursPlot * contoursplot,gdouble xv,gdouble yv,gint * x,gint * y)10563 static void value2pixel(GabeditContoursPlot *contoursplot, gdouble xv, gdouble yv, gint *x, gint *y)
10564 {
10565   g_return_if_fail (contoursplot != NULL);
10566   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10567 
10568   *x=(xv-contoursplot->xmin)*((gdouble)contoursplot->plotting_rect.width)/(contoursplot->xmax-contoursplot->xmin);
10569   if(contoursplot->reflect_x) *x = contoursplot->plotting_rect.width - *x;
10570 
10571   *y=(yv-contoursplot->ymin)*((gdouble)contoursplot->plotting_rect.height)/(contoursplot->ymax-contoursplot->ymin);
10572   if(contoursplot->reflect_y) *y = contoursplot->plotting_rect.height - *y;
10573 }
10574 /****************************************************************************************/
pixel2value(GabeditContoursPlot * contoursplot,gint xp,gint yp,gdouble * x,gdouble * y)10575 static void pixel2value(GabeditContoursPlot *contoursplot, gint xp, gint yp, gdouble *x, gdouble *y)
10576 {
10577   g_return_if_fail (contoursplot != NULL);
10578   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10579   gdouble xxp = (gdouble)xp;
10580   gdouble yyp = (gdouble)yp;
10581   if(contoursplot->reflect_x)  xxp = contoursplot->plotting_rect.width-xxp;
10582   if(contoursplot->reflect_y)  yyp = contoursplot->plotting_rect.height-yyp;
10583 
10584 
10585   *x=contoursplot->xmin+((gdouble)xxp)*(contoursplot->xmax-contoursplot->xmin)/((gdouble)contoursplot->plotting_rect.width);
10586   *y=contoursplot->ymin+((gdouble)yyp)*(contoursplot->ymax-contoursplot->ymin)/((gdouble)contoursplot->plotting_rect.height);
10587 }
10588 /****************************************************************************************/
contoursplot_calculate_colormap_sizes(GabeditContoursPlot * contoursplot)10589 static void contoursplot_calculate_colormap_sizes(GabeditContoursPlot *contoursplot)
10590 {
10591   GtkWidget *widget;
10592 
10593   g_return_if_fail (contoursplot != NULL);
10594 
10595   widget=GTK_WIDGET(contoursplot);
10596 
10597   if (contoursplot->colormap_legends)
10598   {
10599     	pango_layout_set_font_description (contoursplot->colormap_legends[0], widget->style->font_desc);
10600     	pango_layout_get_size(contoursplot->colormap_legends[0], &(contoursplot->colormap_width), &(contoursplot->colormap_height));
10601 	contoursplot->colormap_width /=PANGO_SCALE;
10602 	contoursplot->colormap_height /=PANGO_SCALE;
10603 	contoursplot->colormap_width *=2;
10604   	contoursplot->colormap_height = contoursplot->plotting_rect.height;
10605   }
10606 }
10607 /****************************************************************************************/
contoursplot_build_colormap_legends(GabeditContoursPlot * contoursplot)10608 static void contoursplot_build_colormap_legends(GabeditContoursPlot *contoursplot)
10609 {
10610   GtkWidget *widget;
10611   gint loop;
10612   ColorMap* colorMap = NULL;
10613   gint nlegends;
10614   gdouble vmin;
10615   gdouble dv;
10616   gdouble value;
10617 
10618 
10619   g_return_if_fail (contoursplot != NULL);
10620 
10621   widget=GTK_WIDGET(contoursplot);
10622 
10623   colorMap =GABEDIT_ContoursPLOT(contoursplot)->colorsMap.colorMap;
10624   if(!colorMap) return;
10625   if(colorMap->numberOfColors<2)return;
10626 
10627   nlegends = GABEDIT_ContoursPLOT(contoursplot)->colormap_nlegends;
10628 
10629   contoursplot->colormap_legends=g_new(PangoLayout*, nlegends);
10630   if(contoursplot->colormap_legends_str) g_free(contoursplot->colormap_legends_str);
10631     contoursplot->colormap_legends_str=g_malloc( (sizeof(gchar*) * nlegends));
10632     vmin = colorMap->colorValue[0].value;
10633     dv = (colorMap->colorValue[colorMap->numberOfColors-1].value-colorMap->colorValue[0].value)/(nlegends-1);
10634     for (loop=0; loop<nlegends; loop++)
10635     {
10636       contoursplot->colormap_legends_str[loop]=g_malloc( (sizeof(gchar) * (contoursplot->y_legends_digits+1)));
10637       value = vmin + dv*loop;
10638       snprintf(contoursplot->colormap_legends_str[loop], contoursplot->y_legends_digits+1, "%lf", value);
10639       contoursplot->colormap_legends_str[loop][contoursplot->y_legends_digits]='\0';
10640       /* printf("str[%d]=%s\n",loop, contoursplot->colormap_legends_str[loop]);*/
10641       contoursplot->colormap_legends[loop]=gtk_widget_create_pango_layout (widget, contoursplot->colormap_legends_str[loop]);
10642     }
10643     contoursplot->colormap_nlegends=nlegends;
10644   contoursplot_calculate_colormap_sizes(contoursplot);
10645 }
10646 /****************************************************************************************/
contoursplot_calculate_legends_sizes(GabeditContoursPlot * contoursplot)10647 static void contoursplot_calculate_legends_sizes(GabeditContoursPlot *contoursplot)
10648 {
10649   GtkWidget *widget;
10650 
10651   g_return_if_fail (contoursplot != NULL);
10652 
10653   widget=GTK_WIDGET(contoursplot);
10654 
10655   if (contoursplot->x_legends_digits==0 && contoursplot->y_legends_digits==0){
10656     contoursplot->x_legends_width=0;
10657     contoursplot->x_legends_height=0;
10658     contoursplot->y_legends_width=0;
10659     contoursplot->y_legends_height=0;
10660     return;
10661   }
10662 
10663   if (contoursplot->h_legends)
10664   {
10665     pango_layout_set_font_description (contoursplot->h_legends[0], widget->style->font_desc);
10666     pango_layout_get_size(contoursplot->h_legends[0], &(contoursplot->x_legends_width), &(contoursplot->x_legends_height));
10667   }
10668   if (contoursplot->v_legends)
10669   {
10670 	gint i;
10671     	pango_layout_set_font_description (contoursplot->v_legends[0], widget->style->font_desc);
10672     	pango_layout_get_size(contoursplot->v_legends[0], &(contoursplot->y_legends_width), &(contoursplot->y_legends_height));
10673     	for (i=1; i<contoursplot->vmajor_ticks; i++)
10674     	{
10675 		gint w,h;
10676     		pango_layout_set_font_description (contoursplot->v_legends[i], widget->style->font_desc);
10677     		pango_layout_get_size(contoursplot->v_legends[i], &w,&h);
10678 		if(w>contoursplot->y_legends_width) contoursplot->y_legends_width=w;
10679     	}
10680   }
10681 
10682   contoursplot->x_legends_width/=PANGO_SCALE;
10683   contoursplot->x_legends_height/=PANGO_SCALE;
10684 
10685   contoursplot->y_legends_width/=PANGO_SCALE;
10686   contoursplot->y_legends_height/=PANGO_SCALE;
10687 
10688   contoursplot->h_label_width = 0;
10689   contoursplot->h_label_height =0;
10690   if (contoursplot->h_label)
10691   {
10692     	pango_layout_set_font_description (contoursplot->h_label, widget->style->font_desc);
10693     	pango_layout_get_size(contoursplot->h_label, &(contoursplot->h_label_width), &(contoursplot->h_label_height));
10694 	contoursplot->h_label_width /=PANGO_SCALE;
10695 	contoursplot->h_label_height /=PANGO_SCALE;
10696   }
10697   contoursplot->v_label_width = 0;
10698   contoursplot->v_label_height =0;
10699   if (contoursplot->v_label)
10700   {
10701     	pango_layout_set_font_description (contoursplot->v_label, widget->style->font_desc);
10702     	pango_layout_get_size(contoursplot->v_label, &(contoursplot->v_label_width), &(contoursplot->v_label_height));
10703 	contoursplot->v_label_width /=PANGO_SCALE;
10704 	contoursplot->v_label_height /=PANGO_SCALE;
10705   }
10706 }
10707 /****************************************************************************************/
contoursplot_build_legends(GabeditContoursPlot * contoursplot)10708 static void contoursplot_build_legends(GabeditContoursPlot *contoursplot)
10709 {
10710   GtkWidget *widget;
10711   gint loop;
10712 
10713   g_return_if_fail (contoursplot != NULL);
10714 
10715   widget=GTK_WIDGET(contoursplot);
10716 
10717   if ( (contoursplot->hmajor_ticks > 1) && (contoursplot->x_legends_digits != 0)){
10718     contoursplot->d_hlegend=fabs(contoursplot->xmax-contoursplot->xmin)/((gdouble)contoursplot->hmajor_ticks-1.0);
10719 
10720     contoursplot->h_legends=g_new(PangoLayout*, contoursplot->hmajor_ticks);
10721     if(contoursplot->h_legends_str) g_free(contoursplot->h_legends_str);
10722     contoursplot->h_legends_str = g_malloc( (sizeof(gchar*) * contoursplot->hmajor_ticks ) );
10723     for (loop=0; loop<contoursplot->hmajor_ticks; loop++){
10724       contoursplot->h_legends_str[loop] = g_malloc( (sizeof(gchar) * (contoursplot->x_legends_digits+1)) );
10725       snprintf(contoursplot->h_legends_str[loop] , contoursplot->x_legends_digits+1, "%lf", contoursplot->xmin + (gdouble)loop*contoursplot->d_hlegend);
10726       contoursplot->h_legends_str[loop] [contoursplot->x_legends_digits]='\0';
10727       contoursplot->h_legends[loop]=gtk_widget_create_pango_layout (widget, contoursplot->h_legends_str[loop]);
10728     }
10729   }
10730 
10731   if ((contoursplot->vmajor_ticks > 1) && (contoursplot->y_legends_digits != 0) ){
10732     contoursplot->d_vlegend=fabs(contoursplot->ymax-contoursplot->ymin)/((gdouble)contoursplot->vmajor_ticks-1.0);
10733 
10734     contoursplot->v_legends=g_new(PangoLayout*, contoursplot->vmajor_ticks);
10735     if(contoursplot->v_legends_str) g_free(contoursplot->v_legends_str);
10736     contoursplot->v_legends_str=g_malloc( (sizeof(gchar*) * contoursplot->vmajor_ticks));
10737     for (loop=0; loop<contoursplot->vmajor_ticks; loop++){
10738       contoursplot->v_legends_str[loop]=g_malloc( (sizeof(gchar) * (contoursplot->y_legends_digits+1)));
10739       snprintf(contoursplot->v_legends_str[loop], contoursplot->y_legends_digits+1, "%lf", contoursplot->ymin + (gdouble)loop*contoursplot->d_vlegend);
10740       contoursplot->v_legends_str[loop][contoursplot->y_legends_digits]='\0';
10741       contoursplot->v_legends[loop]=gtk_widget_create_pango_layout (widget, contoursplot->v_legends_str[loop]);
10742     }
10743   }
10744   contoursplot->h_label = get_pango_str(contoursplot, contoursplot->h_label_str);
10745   contoursplot->v_label = get_pango_str(contoursplot, contoursplot->v_label_str);
10746   contoursplot_calculate_legends_sizes(contoursplot);
10747 }
10748 /****************************************************************************************/
contoursplot_free_legends(GabeditContoursPlot * contoursplot)10749 static void contoursplot_free_legends(GabeditContoursPlot *contoursplot)
10750 {
10751   gint loop;
10752 
10753   g_return_if_fail (contoursplot != NULL);
10754 
10755   if (contoursplot->h_legends!=NULL){
10756     for (loop=0; loop<contoursplot->hmajor_ticks; loop++)
10757       if (contoursplot->h_legends[loop]!=NULL)
10758         g_object_unref(G_OBJECT(contoursplot->h_legends[loop]));
10759     g_free(contoursplot->h_legends);
10760     contoursplot->h_legends=NULL;
10761   }
10762 
10763   if (contoursplot->v_legends!=NULL){
10764     for (loop=0; loop<contoursplot->vmajor_ticks; loop++)
10765       if (contoursplot->v_legends[loop]!=NULL)
10766         g_object_unref(G_OBJECT(contoursplot->v_legends[loop]));
10767     g_free(contoursplot->v_legends);
10768     contoursplot->v_legends=NULL;
10769   }
10770   if (contoursplot->v_legends_str!=NULL)
10771   {
10772     	for (loop=0; loop<contoursplot->vmajor_ticks; loop++)
10773 		g_free(contoursplot->v_legends_str[loop]);
10774 	 g_free(contoursplot->v_legends_str);
10775   }
10776   if (contoursplot->h_legends_str!=NULL)
10777   {
10778     	for (loop=0; loop<contoursplot->hmajor_ticks; loop++)
10779 		g_free(contoursplot->h_legends_str[loop]);
10780 	  g_free(contoursplot->h_legends_str);
10781   }
10782   contoursplot->v_legends_str = NULL;
10783   contoursplot->h_legends_str = NULL;
10784 }
10785 /****************************************************************************************/
contoursplot_reflect_x(GabeditContoursPlot * contoursplot,gboolean reflection)10786 static void contoursplot_reflect_x (GabeditContoursPlot *contoursplot, gboolean reflection)
10787 {
10788   g_return_if_fail (contoursplot != NULL);
10789   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10790 
10791   if(contoursplot->reflect_x == reflection) return;
10792 
10793   contoursplot->reflect_x = reflection;
10794   reset_object_text_pixels(contoursplot);
10795   reset_object_line_pixels(contoursplot);
10796   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10797 }
10798 /****************************************************************************************/
gabedit_contoursplot_reflect_x(GabeditContoursPlot * contoursplot,gboolean enable)10799 void gabedit_contoursplot_reflect_x (GabeditContoursPlot *contoursplot, gboolean enable)
10800 {
10801 	GtkUIManager *manager = g_object_get_data(G_OBJECT (contoursplot), "Manager");
10802 	GtkAction* action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderDirections/DirectionReflectX");
10803 	if(action) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),enable);
10804 }
10805 /****************************************************************************************/
contoursplot_reflect_y(GabeditContoursPlot * contoursplot,gboolean reflection)10806 static void contoursplot_reflect_y (GabeditContoursPlot *contoursplot, gboolean reflection)
10807 {
10808   g_return_if_fail (contoursplot != NULL);
10809   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10810 
10811   if(contoursplot->reflect_y == reflection) return;
10812 
10813   contoursplot->reflect_y = reflection;
10814   reset_object_text_pixels(contoursplot);
10815   reset_object_line_pixels(contoursplot);
10816   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10817 }
10818 /****************************************************************************************/
gabedit_contoursplot_reflect_y(GabeditContoursPlot * contoursplot,gboolean enable)10819 void gabedit_contoursplot_reflect_y (GabeditContoursPlot *contoursplot, gboolean enable)
10820 {
10821 	GtkUIManager *manager = g_object_get_data(G_OBJECT (contoursplot), "Manager");
10822 	GtkAction* action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderDirections/DirectionReflectY");
10823 	if(action) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),enable);
10824 }
10825 /****************************************************************************************/
contoursplot_show_label_contours(GabeditContoursPlot * contoursplot,gboolean show)10826 static void contoursplot_show_label_contours (GabeditContoursPlot *contoursplot, gboolean show)
10827 {
10828   g_return_if_fail (contoursplot != NULL);
10829   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10830 
10831   if(contoursplot->show_label_contours == show) return;
10832 
10833   contoursplot->show_label_contours = show;
10834 
10835   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10836 }
10837 /****************************************************************************************/
contoursplot_build_position_label_contours(GabeditContoursPlot * contoursplot)10838 static void contoursplot_build_position_label_contours (GabeditContoursPlot *contoursplot)
10839 {
10840   g_return_if_fail (contoursplot != NULL);
10841   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10842 
10843   reset_label_contours(GTK_WIDGET(contoursplot), NULL);
10844   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10845 }
10846 /****************************************************************************************/
contoursplot_show_colormap(GabeditContoursPlot * contoursplot,gboolean show)10847 static void contoursplot_show_colormap (GabeditContoursPlot *contoursplot, gboolean show)
10848 {
10849   g_return_if_fail (contoursplot != NULL);
10850   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10851 
10852   if(contoursplot->show_colormap == show) return;
10853 
10854   contoursplot->show_colormap = show;
10855   contoursplot_build_colormap_legends(contoursplot);
10856   contoursplot_calculate_colormap_sizes(contoursplot);
10857   contoursplot_calculate_sizes(contoursplot);
10858   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10859 }
10860 /****************************************************************************************/
contoursplot_dashed_negative_contours(GabeditContoursPlot * contoursplot,gboolean dashed)10861 static void contoursplot_dashed_negative_contours (GabeditContoursPlot *contoursplot, gboolean dashed)
10862 {
10863   g_return_if_fail (contoursplot != NULL);
10864   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10865 
10866   if(contoursplot->dashed_negative_contours == dashed) return;
10867 
10868   contoursplot->dashed_negative_contours = dashed;
10869   reset_contour_lines_styles(GTK_WIDGET(contoursplot), NULL);
10870   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10871 }
10872 /****************************************************************************************/
contoursplot_show_left_legends(GabeditContoursPlot * contoursplot,gboolean show)10873 static void contoursplot_show_left_legends (GabeditContoursPlot *contoursplot, gboolean show)
10874 {
10875   g_return_if_fail (contoursplot != NULL);
10876   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10877 
10878   if(contoursplot->show_left_legends == show) return;
10879 
10880   contoursplot->show_left_legends = show;
10881   contoursplot_build_legends(contoursplot);
10882   contoursplot_calculate_legends_sizes(contoursplot);
10883   contoursplot_calculate_sizes(contoursplot);
10884   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10885 }
10886 /****************************************************************************************/
gabedit_contoursplot_show_left_legends(GabeditContoursPlot * contoursplot,gboolean enable)10887 void gabedit_contoursplot_show_left_legends (GabeditContoursPlot *contoursplot, gboolean enable)
10888 {
10889 	GtkUIManager *manager = g_object_get_data(G_OBJECT (contoursplot), "Manager");
10890 	GtkAction* action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderLegends/LegendShowLeft");
10891 	if(action) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),enable);
10892 }
10893 /****************************************************************************************/
contoursplot_show_right_legends(GabeditContoursPlot * contoursplot,gboolean show)10894 static void contoursplot_show_right_legends (GabeditContoursPlot *contoursplot, gboolean show)
10895 {
10896   g_return_if_fail (contoursplot != NULL);
10897   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10898 
10899   if(contoursplot->show_right_legends == show) return;
10900 
10901   contoursplot->show_right_legends = show;
10902   contoursplot_build_legends(contoursplot);
10903   contoursplot_calculate_legends_sizes(contoursplot);
10904   contoursplot_calculate_sizes(contoursplot);
10905   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10906 }
10907 /****************************************************************************************/
gabedit_contoursplot_show_right_legends(GabeditContoursPlot * contoursplot,gboolean enable)10908 void gabedit_contoursplot_show_right_legends (GabeditContoursPlot *contoursplot, gboolean enable)
10909 {
10910 	GtkUIManager *manager = g_object_get_data(G_OBJECT (contoursplot), "Manager");
10911 	GtkAction* action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderLegends/LegendShowRight");
10912 	if(action) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),enable);
10913 }
10914 /****************************************************************************************/
contoursplot_show_top_legends(GabeditContoursPlot * contoursplot,gboolean show)10915 static void contoursplot_show_top_legends (GabeditContoursPlot *contoursplot, gboolean show)
10916 {
10917   g_return_if_fail (contoursplot != NULL);
10918   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10919 
10920   if(contoursplot->show_top_legends == show) return;
10921 
10922   contoursplot->show_top_legends = show;
10923   contoursplot_build_legends(contoursplot);
10924   contoursplot_calculate_legends_sizes(contoursplot);
10925   contoursplot_calculate_sizes(contoursplot);
10926   gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10927 }
10928 /****************************************************************************************/
gabedit_contoursplot_show_top_legends(GabeditContoursPlot * contoursplot,gboolean enable)10929 void gabedit_contoursplot_show_top_legends (GabeditContoursPlot *contoursplot, gboolean enable)
10930 {
10931 	GtkUIManager *manager = g_object_get_data(G_OBJECT (contoursplot), "Manager");
10932 	GtkAction* action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderLegends/LegendShowTop");
10933 	if(action) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),enable);
10934 }
10935 /****************************************************************************************/
contoursplot_show_bottom_legends(GabeditContoursPlot * contoursplot,gboolean show)10936 static void contoursplot_show_bottom_legends (GabeditContoursPlot *contoursplot, gboolean show)
10937 {
10938   g_return_if_fail (contoursplot != NULL);
10939   g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10940 
10941   if(contoursplot->show_bottom_legends == show) return;
10942 
10943   contoursplot->show_bottom_legends = show;
10944   contoursplot_build_legends(contoursplot);
10945   contoursplot_calculate_legends_sizes(contoursplot);
10946   contoursplot_calculate_sizes(contoursplot);
10947    gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10948 }
10949 /****************************************************************************************/
gabedit_contoursplot_show_bottom_legends(GabeditContoursPlot * contoursplot,gboolean enable)10950 void gabedit_contoursplot_show_bottom_legends (GabeditContoursPlot *contoursplot, gboolean enable)
10951 {
10952 	GtkUIManager *manager = g_object_get_data(G_OBJECT (contoursplot), "Manager");
10953 	GtkAction* action = gtk_ui_manager_get_action (manager, "/MenuContoursPlot/Render/RenderLegends/LegendShowBottom");
10954 	if(action) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),enable);
10955 }
10956 /****************************************************************************************/
gabedit_contoursplot_set_font(GabeditContoursPlot * contoursplot,gchar * fontName)10957 void gabedit_contoursplot_set_font (GabeditContoursPlot *contoursplot, gchar* fontName)
10958 {
10959 	GtkWidget* widget = NULL;
10960 	g_return_if_fail (contoursplot != NULL);
10961 	g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10962 	PangoFontDescription *font_desc = pango_font_description_from_string (fontName);
10963 
10964 	widget=GTK_WIDGET(contoursplot);
10965 
10966 	if(font_desc)
10967 	{
10968 		contoursplot->font_size =  contoursplot_get_font_size (widget, font_desc);
10969 		gtk_widget_modify_font (widget, font_desc);
10970   		contoursplot_build_legends(contoursplot);
10971   		contoursplot_calculate_legends_sizes(contoursplot);
10972   		contoursplot_calculate_sizes(contoursplot);
10973 		gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10974 	}
10975 }
10976 /****************************************************************************************/
gabedit_contoursplot_set_x_label(GabeditContoursPlot * contoursplot,G_CONST_RETURN gchar * str)10977 void gabedit_contoursplot_set_x_label (GabeditContoursPlot *contoursplot, G_CONST_RETURN gchar* str)
10978 {
10979 	GtkWidget* widget = NULL;
10980 	g_return_if_fail (contoursplot != NULL);
10981 	g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
10982 	widget=GTK_WIDGET(contoursplot);
10983 
10984   	if(contoursplot->h_label_str) g_free(contoursplot->h_label_str);
10985 	if(str && strlen(str)>0)
10986 	{
10987 		contoursplot->h_label_str = g_strdup(str);
10988 	}
10989 	else
10990 	{
10991 		contoursplot->h_label_str = NULL;
10992 	}
10993 
10994   	contoursplot_build_legends(contoursplot);
10995   	contoursplot_calculate_legends_sizes(contoursplot);
10996   	contoursplot_calculate_sizes(contoursplot);
10997 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
10998 }
10999 /****************************************************************************************/
gabedit_contoursplot_set_y_label(GabeditContoursPlot * contoursplot,G_CONST_RETURN gchar * str)11000 void gabedit_contoursplot_set_y_label (GabeditContoursPlot *contoursplot, G_CONST_RETURN gchar* str)
11001 {
11002 	GtkWidget* widget = NULL;
11003 	g_return_if_fail (contoursplot != NULL);
11004 	g_return_if_fail (GABEDIT_IS_ContoursPLOT (contoursplot));
11005 	widget=GTK_WIDGET(contoursplot);
11006 
11007   	if(contoursplot->v_label_str) g_free(contoursplot->v_label_str);
11008 	if(str && strlen(str)>0)
11009 	{
11010 		contoursplot->v_label_str = g_strdup(str);
11011 	}
11012 	else
11013 		contoursplot->v_label_str = NULL;
11014 
11015   	contoursplot_build_legends(contoursplot);
11016   	contoursplot_calculate_legends_sizes(contoursplot);
11017   	contoursplot_calculate_sizes(contoursplot);
11018 	gtk_widget_queue_draw(GTK_WIDGET(contoursplot));
11019 }
11020 /****************************************************************************************/
contoursplot_motion_notify_event(GtkWidget * contoursplot,GdkEventMotion * event,gpointer user_data)11021 static gboolean contoursplot_motion_notify_event(GtkWidget *contoursplot, GdkEventMotion *event, gpointer user_data)
11022 {
11023 	double xv, yv;
11024 	int x, y;
11025 	char str[50];
11026 	int context_id;
11027 	GtkWidget* statusbar = g_object_get_data(G_OBJECT (contoursplot), "StatusBar");
11028 
11029 	x=event->x;
11030 	y=event->y;
11031 
11032 	if (event->is_hint || (event->window != contoursplot->window))
11033 		gdk_window_get_pointer (contoursplot->window, &x, &y, NULL);
11034 
11035 	if(gabedit_contoursplot_get_point(GABEDIT_ContoursPLOT(contoursplot), x, y, &xv, &yv))
11036 		snprintf(str, 50, "Mouse position: %f, %f", xv, yv);
11037 	else
11038 		sprintf(str, " ");
11039 	context_id=gtk_statusbar_get_context_id (GTK_STATUSBAR(statusbar), "mouse position");
11040 	gtk_statusbar_push (GTK_STATUSBAR(statusbar), context_id, str);
11041 
11042 	return TRUE;
11043 }
11044 /****************************************************************************************/
gabedit_contoursplot_new_window(gchar * title,GtkWidget * parent)11045 GtkWidget* gabedit_contoursplot_new_window(gchar* title, GtkWidget*parent)
11046 {
11047 	GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
11048 	GtkWidget* table = NULL;
11049 	GtkWidget* box = NULL;
11050 	GtkWidget* frame_contoursplot = NULL;
11051 	GtkWidget* contoursplot = NULL;
11052 
11053 	GtkWidget *statusbar = NULL;
11054 
11055 	gtk_window_set_title (GTK_WINDOW (window), title);
11056 	gtk_signal_connect (GTK_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), NULL);
11057 	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
11058 	gtk_window_set_default_size (GTK_WINDOW(window),2*gdk_screen_width()/3,2*gdk_screen_height()/3);
11059 
11060 	table=gtk_table_new(3, 1, FALSE);
11061 	gtk_container_add(GTK_CONTAINER(window), table);
11062 	gtk_widget_show(table);
11063 
11064 	frame_contoursplot=gtk_frame_new("Contours GabeditPlot");
11065 	gtk_table_attach(GTK_TABLE(table), frame_contoursplot, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
11066 	gtk_widget_show(frame_contoursplot);
11067 
11068 	contoursplot = gabedit_contoursplot_new();
11069 	gtk_container_add(GTK_CONTAINER(frame_contoursplot), contoursplot);
11070 	gtk_widget_show (contoursplot);
11071 
11072 	g_object_set_data (G_OBJECT (window), "ContoursPLOT",contoursplot);
11073 
11074 	box=gtk_hbox_new(FALSE,0);
11075 	gtk_table_attach(GTK_TABLE(table), box, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 5, 5);
11076 	gtk_widget_show (box);
11077 	g_object_set_data(G_OBJECT (contoursplot), "Box", box);
11078 
11079 	statusbar=gtk_statusbar_new();
11080 	gtk_table_attach(GTK_TABLE(table), statusbar, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 5, 5);
11081 	gtk_widget_show (statusbar);
11082 	g_object_set_data(G_OBJECT (contoursplot), "StatusBar", statusbar);
11083 
11084 	if(parent) gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(parent));
11085 	gtk_widget_show (window);
11086 
11087         gabedit_contoursplot_set_range(GABEDIT_ContoursPLOT(contoursplot),  0.0,  10,  0,  20);
11088 	gabedit_contoursplot_set_x_legends_digits(GABEDIT_ContoursPLOT(contoursplot), 5);
11089 	gabedit_contoursplot_set_y_legends_digits(GABEDIT_ContoursPLOT(contoursplot), 5);
11090 
11091 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_HMAJOR_GRID, FALSE);
11092 	gabedit_contoursplot_enable_grids (GABEDIT_ContoursPLOT(contoursplot), GABEDIT_ContoursPLOT_VMAJOR_GRID, FALSE);
11093 	gabedit_contoursplot_show_top_legends (GABEDIT_ContoursPLOT(contoursplot),FALSE);
11094 	gabedit_contoursplot_show_right_legends (GABEDIT_ContoursPLOT(contoursplot),FALSE);
11095 
11096 	g_signal_connect_after(G_OBJECT(contoursplot), "motion-notify-event", G_CALLBACK(contoursplot_motion_notify_event), NULL);
11097 
11098 	g_object_set_data(G_OBJECT (contoursplot), "Window", window);
11099 	g_object_set_data(G_OBJECT (window), "Box", box);
11100 
11101 	gabedit_contoursplot_set_font (GABEDIT_ContoursPLOT(contoursplot), "sans 12");
11102 
11103 	return window;
11104 }
11105 /****************************************************************************************/
gabedit_contoursplot_help()11106 void gabedit_contoursplot_help()
11107 {
11108 	GtkWidget* dialog = NULL;
11109 	GtkWidget *label, *button;
11110 	GtkWidget *frame, *vboxframe;
11111 	GtkWidget* hbox;
11112 
11113 	gchar* tmp = g_strdup_printf(
11114 			_(
11115 			"Mouse buttons and Keys :\n"
11116 			"\t Right button : popup menu\n"
11117 			"\t Middle button : zoom\n"
11118 			"\t Left button + Control key : zoom\n"
11119 			"\t Left button + Shift key : compute distance between 2 points\n"
11120 			"\t d key : compute f and its dervivatives, using a bicubic interpolation\n"
11121 			"\t Left button + t key : insert a text\n"
11122 			"\t Left button + l key : insert a line (arrow)\n"
11123 			"\t Left button + i key : insert an image (arrow)\n"
11124 			"\t Left button + r key : remove selected image/text/line\n"
11125 			"\t Left button, double click : select a data to change\n"
11126 			"\n\n"
11127 			"Popup menu :\n"
11128 			"\t Set : ticks, margins, ranges, X and Y labels, digits, font size, auto ranges\n"
11129 			"\t Render : grids, directions, legends, colormap\n"
11130 			"\t Data : read data from a grid ASCII file (txt)\n"
11131 			"\t        Save all data at a txt file\n"
11132 			"\t        Remove all all\n"
11133 			"\t Contours : set values or delete contours\n"
11134 			"\t ColorMap : set colormap\n"
11135 			"\t Objects : for insert/delete texts, lines or images\n"
11136 			"\t Screen capture : BMP, JPEG, PNG, Transparent PNG, TIF\n"
11137 			"\t Export image : SVG, PS, EPS and PDF (this is a real export, not a capture)\n"
11138 			"\t Read : read all (parameters, data, texts, lines, images) from a Gabedit file\n"
11139 			"\t Save : save all (parameters, data, texts, lines, images) in Gabedit file\n"
11140 			"\t Help : for obtain this window (You guessed :))\n"
11141 			"\t Close : very simple :)\n"
11142 			)
11143 			);
11144 
11145 	dialog = gtk_dialog_new();
11146 	gtk_widget_realize(GTK_WIDGET(dialog));
11147 
11148 	gtk_window_set_title(GTK_WINDOW(dialog),_("Help"));
11149 	g_signal_connect(G_OBJECT(dialog), "delete_event", (GCallback)gtk_widget_destroy, NULL);
11150 	frame = gtk_frame_new (NULL);
11151 	gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
11152 	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
11153 	gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog)->vbox), frame,TRUE,TRUE,0);
11154 
11155 	gtk_widget_show (frame);
11156   	vboxframe = gtk_vbox_new (FALSE, 0);
11157 	gtk_container_add(GTK_CONTAINER(frame), vboxframe);
11158     	label = gtk_label_new(tmp);
11159   	gtk_widget_show (label);
11160    	gtk_label_set_justify(GTK_LABEL(label),GTK_JUSTIFY_LEFT);
11161   	hbox = gtk_hbox_new (FALSE, 5);
11162   	gtk_box_pack_start (GTK_BOX (vboxframe), hbox, FALSE, FALSE, 5);
11163   	gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 5);
11164   	gtk_widget_show (hbox);
11165 
11166 	gtk_box_set_homogeneous (GTK_BOX( GTK_DIALOG(dialog)->action_area), FALSE);
11167 	button = gtk_button_new_from_stock (GTK_STOCK_OK);
11168 	gtk_box_pack_end (GTK_BOX( GTK_DIALOG(dialog)->action_area), button, FALSE, TRUE, 5);
11169 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
11170 	gtk_widget_grab_default(button);
11171 	g_signal_connect_swapped(G_OBJECT(button), "clicked",
11172                           (GCallback)gtk_widget_destroy,
11173                           GTK_OBJECT(dialog));
11174 
11175 	gtk_widget_show_all(dialog);
11176        gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
11177        g_free(tmp);
11178 }
11179