atomes 1.3.1
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-2026 by CNRS and University of Strasbourg */
15
21
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 Curve * this_curve = get_curve_from_pointer (curve);
86 pid = ((tint *)curve) -> a;
87 rid = ((tint *)curve) -> b;
88 cid = ((tint *)curve) -> c;
89
90 cairo_surface_t * surface = NULL;
91 project * this_proj = get_project_by_id(pid);
92
93 where = this_curve -> format;
94 // g_print ("where= %d, width = %d, height= %d\n", where, width, height);
95 this_curve -> format = 0;
96 if (where == 0)
97 {
98 alp=1.0;
99#ifdef GTK3
100 this_curve -> wsize[0] = get_widget_width (grwdget);
101 this_curve -> wsize[1] = get_widget_height (grwdget);
102#else
103 this_curve -> wsize[0] = width;
104 this_curve -> wsize[1] = height;
105#endif
106 for (j=0; j<2; j++)
107 {
108 resol[j] = this_curve -> wsize[j];
109 if (this_curve -> curve_edit)
110 {
111 if (this_curve -> curve_edit -> xyp[j] != NULL) update_entry_int (GTK_ENTRY(this_curve -> curve_edit -> xyp[j]), this_curve -> wsize[j]);
112 }
113 }
114 }
115 else
116 {
117 alp=0.0;
118 if (where == 1)
119 {
120 alp = back_alpha;
121 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, resol[0], resol[1]);
122 }
123 else if (where == 2)
124 {
125 alp=1.0;
126 surface = cairo_pdf_surface_create (curve_image_file, (double)resol[0], (double)resol[1]);
127 }
128 else if (where == 3)
129 {
130 alp = back_alpha;
131 surface = cairo_svg_surface_create (curve_image_file, (double)resol[0], (double)resol[1]);
132 }
133 else if (where == 4)
134 {
135 surface = cairo_ps_surface_create (curve_image_file, (double)resol[0], (double)resol[1]);
136 }
137 cr = cairo_create (surface);
138 }
139// Painting the background
140 cairo_set_source_rgba (cr, this_curve -> backcolor.red,
141 this_curve -> backcolor.green,
142 this_curve -> backcolor.blue, alp);
143 cairo_paint (cr);
144 cairo_set_source_rgba (cr, this_curve -> backcolor.red,
145 this_curve -> backcolor.green,
146 this_curve -> backcolor.blue, 1.0);
147
148// Creating Pango Font Layout
149 layout = pango_cairo_create_layout (cr);
150
151 upm = FALSE;
152// Autoscale and autoticking for X and or Y axis
153 for (j=0; j<2; j++)
154 {
155 if (this_curve -> autoscale[j])
156 {
157 // Autoscale
158 autoscale_axis (this_proj, this_curve, rid, cid, j);
159 this_curve -> autoscale[j] = FALSE;
160 // Autoticking
161 this_curve -> majt[j] = scale (this_curve -> axmax[j] - this_curve -> axmin[j]);
162 this_curve -> mint[j] = 2;
163 upm = TRUE;
164 }
165 cxy[j] = this_curve -> axmin[j];
166 }
167 xmax = this_curve -> axmax[0] - cxy[0];
168 ymax = this_curve -> axmax[1] - cxy[1];
169// Ensuring no log scale issuesthis_curve -> extrac
170 if (this_curve -> scale[0]) setup_xaxis_log (cr, this_curve, rid, cid, FALSE);
171 if (this_curve -> scale[1]) setup_yaxis_log (cr, this_curve, FALSE);
172
173 if (upm)
174 {
175 if (this_curve -> curve_edit)
176 {
177 if (this_curve -> curve_edit -> axischoice != NULL)
178 {
179 j = combo_get_active (this_curve -> curve_edit -> axischoice);
180 update_entry_double (GTK_ENTRY(this_curve -> curve_edit -> vmin), this_curve -> axmin[j]);
181 update_entry_double (GTK_ENTRY(this_curve -> curve_edit -> vmax), this_curve -> axmax[j]);
182 update_entry_double (GTK_ENTRY(this_curve -> curve_edit -> majt), this_curve -> majt[j]);
183 update_entry_int (GTK_ENTRY(this_curve -> curve_edit -> nmi[j]), this_curve -> mint[j] - 1);
184 }
185 }
186 }
187
188 prep_plot (this_curve);
189
190// let's go for the plot
191// first we start by the possible extra curves
192 i = 0;
193 CurveExtra * ctmp = this_curve -> extrac -> last;
194 for ( j=0 ; j < this_curve -> extrac -> extras + 1; j++ )
195 {
196 if (this_curve -> draw_id == j)
197 {
198 if (this_curve -> bshift && this_curve -> layout -> aspect && this_curve -> extrac -> extras) i ++;
199 k = (this_curve -> layout -> aspect) ? i : 0;
200 draw_curve (cr,
201 cid,
202 rid,
203 this_proj,
204 this_curve -> ndata,
205 this_curve -> layout -> datacolor,
206 this_curve -> scale[0],
207 this_curve -> scale[1],
208 this_curve -> layout -> aspect,
209 this_curve -> layout -> dash,
210 this_curve -> layout -> thickness,
211 this_curve -> layout -> glyph,
212 this_curve -> layout -> gsize,
213 this_curve -> layout -> gfreq,
214 this_curve -> layout -> hwidth,
215 this_curve -> layout -> hopac,
216 this_curve -> layout -> hpos,
217 this_curve -> extrac -> extras,
218 k);
219 }
220 else
221 {
222 if (this_curve -> bshift && ctmp -> layout -> aspect) i++;
223 k = (ctmp -> layout -> aspect) ? i : 0;
224 draw_curve (cr,
225 ctmp -> id.c,
226 ctmp -> id.b,
227 get_project_by_id(ctmp -> id.a),
228 get_project_by_id(ctmp -> id.a) -> analysis[ctmp -> id.b] -> curves[ctmp -> id.c] -> ndata,
229 ctmp -> layout -> datacolor,
230 this_curve -> scale[0],
231 this_curve -> scale[1],
232 ctmp -> layout -> aspect,
233 ctmp -> layout -> dash,
234 ctmp -> layout -> thickness,
235 ctmp -> layout -> glyph,
236 ctmp -> layout -> gsize,
237 ctmp -> layout -> gfreq,
238 ctmp -> layout -> hwidth,
239 ctmp -> layout -> hopac,
240 ctmp -> layout -> hpos,
241 this_curve -> extrac -> extras,
242 k);
243 if (ctmp -> prev != NULL) ctmp = ctmp -> prev;
244 }
245 }
246 // Draw the axis bars - in option
247 if (this_curve -> show_axis[1])
248 {
249 if (this_curve -> axmin[0] < 0.0 && this_curve -> 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_curve -> axmin[0] * XDRAW / xmax, y_min);
255 cairo_line_to (cr, x_min - this_curve -> axmin[0] * XDRAW / xmax, y_max);
256 cairo_stroke (cr);
257 }
258 }
259
260 if (this_curve -> show_axis[0])
261 {
262 if (this_curve -> axmin[1] < 0.0 && this_curve -> 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_curve -> axmin[1] * YDRAW / ymax);
268 cairo_line_to (cr, x_max, y_min - this_curve -> axmin[1] * YDRAW / ymax);
269 cairo_stroke (cr);
270 }
271 }
272 // Maybe show the frame
273 if (this_curve -> show_frame) draw_frame (cr, this_curve, rid, cid);
274 // maybe for the title
275 if (this_curve -> show_title) show_title (cr, this_curve);
276 // and maybe for the legend
277 if (this_curve -> show_legend) show_legend (cr, this_proj, rid, cid);
278
279 // and we plot the complete curve
280 if (where == 0)
281 {
282 this_curve -> 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_curve -> displayed = TRUE;
300#ifdef GTK3
301 return TRUE;
302#endif
303}
304
312void hide_curve (gpointer data)
313{
314 tint * idc = (tint *)data;
315 Curve * this_curve = get_curve_from_pointer (data);
316 hide_the_widgets (this_curve -> window);
317 if (idc -> a == activep)
318 {
319 adjust_tool_model (idc -> b, idc -> c, this_curve -> path);
320 }
321}
322
323#ifdef GTK4
332G_MODULE_EXPORT gboolean to_hide_curve (GtkWindow * thecurve, gpointer data)
333#else
343G_MODULE_EXPORT gboolean to_hide_curve (GtkWidget * thecurve, GdkEvent * event, gpointer data)
344#endif
345{
346 hide_curve (data);
347 return TRUE;
348}
double cxy[2]
Definition curve.c:72
double xmax
Definition curve.c:68
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:205
int resol[2]
Definition curve.c:65
void prep_plot(Curve *this_curve)
prepare curve plot (setting up variables for the plot)
Definition curve.c:326
double YDRAW
Definition curve.c:66
Curve * get_curve_from_pointer(gpointer data)
get Curve pointer from pointer
Definition curve.c:313
const double pdashed[]
Definition curve.c:125
double XDRAW
Definition curve.c:66
double y_max
Definition curve.c:70
double x_max
Definition curve.c:69
int lenp
Definition curve.c:126
double y_min
Definition curve.c:70
PangoLayout * layout
Definition curve.c:80
double x_min
Definition curve.c:69
char * curve_image_file
Definition curve.c:89
double ymax
Definition curve.c:68
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
GtkWidget * xyp[2]
GtkWidget * majt
GtkWidget * vmin
void show_title(cairo_t *cr, Curve *this_curve)
draw title
Definition title.c:104
GtkWidget * nmi[2]
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_yaxis_log(cairo_t *cr, Curve *this_curve, gboolean draw_it)
setup y axis using a log scale
Definition yaxis.c:224
void show_legend(cairo_t *cr, project *this_proj, int rid, int cid)
draw legend
Definition legend.c:56
double back_alpha
Definition w_img.c:58
void draw_frame(cairo_t *cr, Curve *this_curve, int rid, int cid)
draw frame and axis data
Definition frame.c:163
void setup_xaxis_log(cairo_t *cr, Curve *this_curve, int rid, int cid, gboolean draw_it)
setup x axis using a log scale
Definition xaxis.c:159
GtkWidget * axischoice
void autoscale_axis(project *this_proj, Curve *this_curve, int rid, int cid, int aid)
autoscale axis
Definition yaxis.c:56
GtkWidget * vmax
Definition curve.h:58
GtkTreePath * path
Definition datab.c:103
int activep
Definition global.c:162
Global variable declarations Global convenience function declarations Global data structure defin...
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:935
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:688
int get_widget_height(GtkWidget *widg)
retrive GtkWidget height
Definition gtk-misc.c:2589
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:669
int get_widget_width(GtkWidget *widg)
retrive GtkWidget width
Definition gtk-misc.c:2573
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:224
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:99
void adjust_tool_model(int calc, int curve, gchar *string_path)
adjust the content of the tool box tree model
Definition tools.c:233
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:343
Definition global.h:118