atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
show.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'show.c'
24*
25* Contains:
26*
27
28 - The functions to draw the complete graph
29
30*
31* List of functions:
32
33 gboolean show_curve (GtkWidget * grwdget, cairo_t * cr, gpointer curve);
34
35 G_MODULE_EXPORT gboolean to_hide_curve (GtkWindow * thecurve, gpointer data);
36 G_MODULE_EXPORT gboolean to_hide_curve (GtkWidget * thecurve, GdkEvent * event, gpointer data);
37
38 void show_curve (GtkDrawingArea * area, cairo_t * cr, int width, int height, gpointer curve);
39 void hide_curve (gpointer data);
40
41*/
42
43#include <gtk/gtk.h>
44#include <cairo.h>
45#include <cairo-pdf.h>
46#include <cairo-ps.h>
47#include <cairo-svg.h>
48
49#include "global.h"
50#include "curve.h"
51
52extern void adjust_tool_model (int calc, int curve, gchar * string_path);
53
54#ifdef GTK3
64gboolean show_curve (GtkWidget * grwdget, cairo_t * cr, gpointer curve)
65#else
77void show_curve (GtkDrawingArea * area, cairo_t * cr, int width, int height, gpointer curve)
78#endif
79{
80 int pid, rid, cid;
81 int where;
82 int i, j, k;
83 double alp;
84 gboolean upm;
85 tint * cd = (tint *)curve;
86
87 pid = cd -> a;
88 rid = cd -> b;
89 cid = cd -> c;
90 activec = cid;
91 activer = rid;
92 cairo_surface_t * surface = NULL;
93
94 project * this_proj = get_project_by_id(pid);
95
96 where = this_proj -> curves[rid][cid] -> format;
97 // g_print ("where= %d, width = %d, height= %d\n", where, width, height);
98
99 this_proj -> curves[rid][cid] -> format = 0;
100 if (where == 0)
101 {
102 alp=1.0;
103#ifdef GTK3
104 this_proj -> curves[rid][cid] -> wsize[0] = get_widget_width (grwdget);
105 this_proj -> curves[rid][cid] -> wsize[1] = get_widget_height (grwdget);
106#else
107 this_proj -> curves[rid][cid] -> wsize[0] = width;
108 this_proj -> curves[rid][cid] -> wsize[1] = height;
109#endif
110 for (j=0; j<2; j++)
111 {
112 resol[j] = this_proj -> curves[rid][cid] -> wsize[j];
113 if (xyp[j] != NULL) update_entry_int (GTK_ENTRY(xyp[j]), this_proj -> curves[rid][cid] -> wsize[j]);
114 }
115 }
116 else
117 {
118 alp=0.0;
119 if (where == 1)
120 {
121 alp = back_alpha;
122 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, resol[0], resol[1]);
123 }
124 else if (where == 2)
125 {
126 alp=1.0;
127 surface = cairo_pdf_surface_create (curve_image_file, (double)resol[0], (double)resol[1]);
128 }
129 else if (where == 3)
130 {
131 alp = back_alpha;
132 surface = cairo_svg_surface_create (curve_image_file, (double)resol[0], (double)resol[1]);
133 }
134 else if (where == 4)
135 {
136 surface = cairo_ps_surface_create (curve_image_file, (double)resol[0], (double)resol[1]);
137 }
138 cr = cairo_create (surface);
139 }
140// Painting the background
141 cairo_set_source_rgba (cr, this_proj -> curves[rid][cid] -> backcolor.red,
142 this_proj -> curves[rid][cid] -> backcolor.green,
143 this_proj -> curves[rid][cid] -> backcolor.blue, alp);
144 cairo_paint (cr);
145 cairo_set_source_rgba (cr, this_proj -> curves[rid][cid] -> backcolor.red,
146 this_proj -> curves[rid][cid] -> backcolor.green,
147 this_proj -> curves[rid][cid] -> backcolor.blue, 1.0);
148
149// Creating Pango Font Layout
150 layout = pango_cairo_create_layout (cr);
151
152 upm = FALSE;
153// Autoscale and autoticking for X and or Y axis
154 for (j=0; j<2; j++)
155 {
156 if (this_proj -> curves[rid][cid] -> autoscale[j])
157 {
158 // Autoscale
159 autoscale_axis (this_proj, rid, cid, j);
160 this_proj -> curves[rid][cid] -> autoscale[j] = FALSE;
161 // Autoticking
162 this_proj -> curves[rid][cid] -> majt[j] = scale (this_proj -> curves[rid][cid] -> axmax[j] - this_proj -> curves[rid][cid] -> axmin[j]);
163 this_proj -> curves[rid][cid] -> mint[j] = 2;
164 upm = TRUE;
165 }
166 cxy[j] = this_proj -> curves[rid][cid] -> axmin[j];
167 }
168 xmax = this_proj -> curves[rid][cid] -> axmax[0] - cxy[0];
169 ymax = this_proj -> curves[rid][cid] -> axmax[1] - cxy[1];
170// Ensuring no log scale issues
171 if (this_proj -> curves[rid][cid] -> scale[0]) setup_xaxis_log (cr, this_proj, rid, cid, FALSE);
172 if (this_proj -> curves[rid][cid] -> scale[1]) setup_yaxis_log (cr, this_proj, rid, cid, FALSE);
173
174 if (upm)
175 {
176 if (axischoice != NULL)
177 {
178 j = gtk_combo_box_get_active (GTK_COMBO_BOX(axischoice));
179 update_entry_double (GTK_ENTRY(vmin), this_proj -> curves[rid][cid] -> axmin[j]);
180 update_entry_double (GTK_ENTRY(vmax), this_proj -> curves[rid][cid] -> axmax[j]);
181 update_entry_double (GTK_ENTRY(majt), this_proj -> curves[rid][cid] -> majt[j]);
182 update_entry_int (GTK_ENTRY(nmi[j]), this_proj -> curves[rid][cid] -> mint[j] - 1);
183 }
184 }
185
186 prep_plot (this_proj, rid, cid);
187
188// let's go for the plot
189// first we start by the possible extra curves
190 i = 0;
191 CurveExtra * ctmp = this_proj -> curves[rid][cid] -> extrac -> last;
192 for ( j=0 ; j < this_proj -> curves[rid][cid] -> extrac -> extras + 1; j++ )
193 {
194 if (this_proj -> curves[rid][cid] -> draw_id == j)
195 {
196 if (this_proj -> curves[rid][cid] -> bshift && this_proj -> curves[rid][cid] -> layout -> aspect && this_proj -> curves[rid][cid] -> extrac -> extras) i ++;
197 k = (this_proj -> curves[rid][cid] -> layout -> aspect) ? i : 0;
198 draw_curve (cr,
199 cid,
200 rid,
201 this_proj,
202 this_proj -> curves[rid][cid] -> ndata,
203 this_proj -> curves[rid][cid] -> layout -> datacolor,
204 this_proj -> curves[rid][cid] -> scale[0],
205 this_proj -> curves[rid][cid] -> scale[1],
206 this_proj -> curves[rid][cid] -> layout -> aspect,
207 this_proj -> curves[rid][cid] -> layout -> dash,
208 this_proj -> curves[rid][cid] -> layout -> thickness,
209 this_proj -> curves[rid][cid] -> layout -> glyph,
210 this_proj -> curves[rid][cid] -> layout -> gsize,
211 this_proj -> curves[rid][cid] -> layout -> gfreq,
212 this_proj -> curves[rid][cid] -> layout -> hwidth,
213 this_proj -> curves[rid][cid] -> layout -> hopac,
214 this_proj -> curves[rid][cid] -> layout -> hpos,
215 this_proj -> curves[rid][cid] -> extrac -> extras,
216 k);
217
218 }
219 else
220 {
221 if (this_proj -> curves[rid][cid] -> bshift && ctmp -> layout -> aspect) i++;
222 k = (ctmp -> layout -> aspect) ? i : 0;
223 draw_curve (cr,
224 ctmp -> id.c,
225 ctmp -> id.b,
226 get_project_by_id(ctmp -> id.a),
227 get_project_by_id(ctmp -> id.a) -> curves[ctmp -> id.b][ctmp -> id.c] -> ndata,
228 ctmp -> layout -> datacolor,
229 this_proj -> curves[rid][cid] -> scale[0],
230 this_proj -> curves[rid][cid] -> scale[1],
231 ctmp -> layout -> aspect,
232 ctmp -> layout -> dash,
233 ctmp -> layout -> thickness,
234 ctmp -> layout -> glyph,
235 ctmp -> layout -> gsize,
236 ctmp -> layout -> gfreq,
237 ctmp -> layout -> hwidth,
238 ctmp -> layout -> hopac,
239 ctmp -> layout -> hpos,
240 this_proj -> curves[rid][cid] -> extrac -> extras,
241 k);
242 if (ctmp -> prev != NULL) ctmp = ctmp -> prev;
243 }
244 }
245
246 // Draw the axis bars - in option
247 if (this_proj -> curves[rid][cid] -> show_axis[1])
248 {
249 if (this_proj -> curves[rid][cid] -> axmin[0] < 0.0 && this_proj -> curves[rid][cid] -> axmax[0] > 0.0)
250 {
251 cairo_set_line_width (cr, 1.0);
252 cairo_set_dash (cr, pdashed, lenp, 0.0);
253 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
254 cairo_move_to (cr, x_min - this_proj -> curves[rid][cid] -> axmin[0] * XDRAW / xmax, y_min);
255 cairo_line_to (cr, x_min - this_proj -> curves[rid][cid] -> axmin[0] * XDRAW / xmax, y_max);
256 cairo_stroke (cr);
257 }
258 }
259
260 if (this_proj -> curves[rid][cid] -> show_axis[0])
261 {
262 if (this_proj -> curves[rid][cid] -> axmin[1] < 0.0 && this_proj -> curves[rid][cid] -> axmax[1] > 0.0)
263 {
264 cairo_set_line_width (cr, 1.0);
265 cairo_set_dash (cr, pdashed, lenp, 0.0);
266 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
267 cairo_move_to (cr, x_min, y_min - this_proj -> curves[rid][cid] -> axmin[1] * YDRAW / ymax);
268 cairo_line_to (cr, x_max, y_min - this_proj -> curves[rid][cid] -> axmin[1] * YDRAW / ymax);
269 cairo_stroke (cr);
270 }
271 }
272 // Maybe show the frame
273 if (this_proj -> curves[rid][cid] -> show_frame) draw_frame (cr, this_proj, rid, cid);
274 // maybe for the title
275 if (this_proj -> curves[rid][cid] -> show_title) show_title (cr, this_proj, rid, cid);
276 // and maybe for the legend
277 if (this_proj -> curves[rid][cid] -> show_legend) show_legend (cr, this_proj, rid, cid);
278
279 // and we plot the complete curve
280 if (where == 0)
281 {
282 this_proj -> curves[rid][cid] -> surface = cairo_surface_reference (cairo_get_target (cr));
283 }
284 else if (where == 1)
285 {
286 cairo_surface_write_to_png (surface, curve_image_file);
287 cairo_surface_destroy (surface);
288 }
289 else if (where == 2 || where == 4)
290 {
291 cairo_show_page (cr);
292 cairo_surface_destroy (surface);
293 }
294 else if (where == 3)
295 {
296 cairo_surface_destroy (surface);
297 }
298 if (where > 0) cairo_destroy (cr);
299 this_proj -> curves[rid][cid] -> displayed = TRUE;
300#ifdef GTK3
301 return TRUE;
302#endif
303}
304
312void hide_curve (gpointer data)
313{
314 tint * idc = (tint *)data;
315 hide_the_widgets (get_project_by_id(idc -> a) -> curves[idc -> b][idc -> c] -> window);
316 if (idc -> a == activep)
317 {
318 adjust_tool_model (idc -> b, idc -> c, get_project_by_id(idc -> a) -> curves[idc -> b][idc -> c] -> path);
319 }
320}
321
322#ifdef GTK4
331G_MODULE_EXPORT gboolean to_hide_curve (GtkWindow * thecurve, gpointer data)
332#else
342G_MODULE_EXPORT gboolean to_hide_curve (GtkWidget * thecurve, GdkEvent * event, gpointer data)
343#endif
344{
345 hide_curve (data);
346 return TRUE;
347}
GtkWidget * xyp[2]
Definition cedit.c:87
double cxy[2]
Definition curve.c:71
double xmax
Definition curve.c:67
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:204
int resol[2]
Definition curve.c:64
void prep_plot(project *this_proj, int rid, int cid)
prepare curve plot (setting up variables for the plot)
Definition curve.c:315
double YDRAW
Definition curve.c:65
const double pdashed[]
Definition curve.c:124
double XDRAW
Definition curve.c:65
double y_max
Definition curve.c:69
double x_max
Definition curve.c:68
int lenp
Definition curve.c:125
double y_min
Definition curve.c:69
PangoLayout * layout
Definition curve.c:79
double x_min
Definition curve.c:68
char * curve_image_file
Definition curve.c:88
double ymax
Definition curve.c:67
Variable declarations for the curve widget Functions for interactions with the curve widget.
void show_frame(cairo_t *cd, int tf, int da, int res[2], double ti, double x[2], double y[2], ColRGBA dcol)
draw frame
Definition frame.c:81
void setup_yaxis_log(cairo_t *cr, project *this_proj, int rid, int cid, gboolean draw_it)
setup y axis using a log scale
Definition yaxis.c:231
GtkWidget * majt
Definition tab-4.c:103
int activer
Definition w_curve.c:74
void draw_frame(cairo_t *cr, project *this_proj, int rid, int cid)
draw frame and axis data
Definition frame.c:165
GtkWidget * vmin
Definition tab-4.c:104
GtkWidget * nmi[2]
Definition tab-4.c:106
void draw_curve(cairo_t *cr, int cid, int rid, project *this_proj, int points, ColRGBA withcolor, int xscale, int yscale, int asp, int vdash, double thick, int glyp, double gize, int freq, double hwidth, double hopac, int hpos, int extra, int pid)
draw target curve to the cairo drawing context
Definition draw.c:85
void setup_xaxis_log(cairo_t *cr, project *this_proj, int rid, int cid, gboolean draw_it)
setup x axis using a log scale
Definition xaxis.c:163
void show_legend(cairo_t *cr, project *this_proj, int rid, int cid)
draw legend
Definition legend.c:56
void show_title(cairo_t *cr, project *this_proj, int rid, int cid)
draw title
Definition title.c:107
void autoscale_axis(project *this_proj, int rid, int cid, int aid)
autoscale axis
Definition yaxis.c:55
int activec
Definition w_curve.c:73
double back_alpha
Definition w_img.c:58
GtkWidget * axischoice
Definition tab-4.c:90
GtkWidget * vmax
Definition curve.h:58
GtkTreePath * path
Definition datab.c:103
int activep
Definition global.c:159
Global variable declarations Global convenience function declarations Global data structure defin...
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:633
int get_widget_height(GtkWidget *widg)
retrive GtkWidget height
Definition gtk-misc.c:2419
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:614
int get_widget_width(GtkWidget *widg)
retrive GtkWidget width
Definition gtk-misc.c:2403
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:189
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void autoscale(gpointer data)
autoscale callback
Definition m_curve.c:100
void adjust_tool_model(int calc, int curve, gchar *string_path)
adjust the content of the tool box tree model
Definition tools.c:216
void hide_curve(gpointer data)
hide curve
Definition show.c:312
void show_curve(GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer curve)
show curve callback GTK3
Definition show.c:77
G_MODULE_EXPORT gboolean to_hide_curve(GtkWidget *thecurve, GdkEvent *event, gpointer data)
hide curve callback GTK3
Definition show.c:342
Definition global.h:104
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * show_axis
Definition tab-4.c:97