atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cwidget.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: 'cwidget.c'
24*
25* Contains:
26*
27
28 - The initialization of the curve widget
29
30*
31* List of functions:
32
33 void curve_default_scale (project * this_proj, int rid, int cid, Curve * this_curve);
34 void initcurve (project * pid, int rid, int cid);
35 void init_curve_title (project * this_proj, int rid, int cid);
36 void add_curve_widgets (project * this_proj, int rid);
37
38 DataLayout * curve_default_layout (project * pid, int rid, int cid);
39
40*/
41
42#include <gtk/gtk.h>
43#include <stdlib.h>
44
45#include "global.h"
46#include "interface.h"
47#include "curve.h"
48
58DataLayout * curve_default_layout (project * pid, int rid, int cid)
59{
60 DataLayout * layout = g_malloc0(sizeof*layout);
61 layout -> datacolor.red = RED;
62 layout -> datacolor.green = GREEN;
63 layout -> datacolor.blue = BLUE;
64 layout -> datacolor.alpha = 1.0;
65 layout -> thickness = DTHICK;
66 layout -> hwidth = (rid == SPH) ? 1.0 : pid -> analysis[rid] -> delta;
67 layout -> hopac = 0.25;
68 layout -> hpos = 1;
69 layout -> dash = 1;
70 layout -> gfreq = 1;
71 if (rid < RIN)
72 {
73 layout -> aspect = 0;
74 layout -> glyph = 0;
75 layout -> gsize = 10;
76 }
77 else if (rid == RIN)
78 {
79 if ( cid%4 == 0 || cid%4 == 1 )
80 {
81 layout -> aspect = 1;
82 layout -> glyph = 0;
83 layout -> gsize = 10;
84 }
85 else
86 {
87 layout -> aspect = 0;
88 layout -> glyph = 13;
89 layout -> gsize = 5.0;
90 }
91 }
92 else if (rid < MSD)
93 {
94 layout -> aspect = 1;
95 layout -> glyph = 0;
96 layout -> gsize = 10;
97 }
98 else
99 {
100 layout -> aspect = 0;
101 layout -> glyph = 0;
102 layout -> gsize = 10;
103 }
104 return layout;
105}
106
117void curve_default_scale (project * this_proj, int rid, int cid, Curve * this_curve)
118{
119 if (rid < RIN || rid == MSD || rid == SKT)
120 {
121 this_curve -> cmin[0] = this_proj -> analysis[rid] -> min;
122 this_curve -> cmax[0] = this_proj -> analysis[rid] -> max;
123 }
124 else
125 {
126 this_curve -> cmin[0] = 1.0;
127 this_curve -> cmax[0] = this_curve -> ndata;
128 }
129
130 if (rid != MSD)
131 {
132 this_curve -> scale[0] = 0;
133 this_curve -> scale[1] = 0;
134 }
135 else
136 {
137 if (cid < active_project -> analysis[MSD] -> numc - 6 )
138 {
139 this_curve -> scale[0] = 1;
140 this_curve -> scale[1] = 1;
141 }
142 else
143 {
144 this_curve -> scale[0] = 0;
145 this_curve -> scale[1] = 0;
146 }
147 }
148}
149
159void initcurve (project * pid, int rid, int cid)
160{
161 int k;
162 Curve * this_curve = pid -> analysis[rid] -> curves[cid];
163 this_curve -> window = NULL;
164 this_curve -> plot = NULL;
165 this_curve -> wsize[0] = 800;
166 this_curve -> wsize[1] = 600;
167 this_curve -> show_title = FALSE;
168 this_curve -> default_title = TRUE;
169 this_curve -> title_font = g_strdup_printf ("Sans Bold 12");
170 this_curve -> title_pos[0] = 0.4;
171 this_curve -> title_pos[1] = 0.05;
172 this_curve -> title_color.red = 0.0;
173 this_curve -> title_color.blue = 0.0;
174 this_curve -> title_color.green = 0.0;
175 this_curve -> title_color.alpha = 1.0;
176 this_curve -> format = 0;
177 for (k=0 ; k<2; k++)
178 {
179 if (this_curve -> data[k] != NULL)
180 {
181 g_free (this_curve -> data[k]);
182 this_curve -> data[k] = NULL;
183 }
184 this_curve -> autoscale[k] = TRUE;
185 this_curve -> show_grid[k] = FALSE;
186 this_curve -> show_axis[k] = TRUE;
187 this_curve -> labels_digit[k] = 1;
188 this_curve -> ticks_io[k] = 0;
189 this_curve -> labels_angle[k] = 0.0;
190 this_curve -> labels_font[k] = g_strdup_printf ("Sans 12");
191 this_curve -> mint_size[k] = 5;
192 this_curve -> majt_size[k] = 10;
193 this_curve -> axis_defaut_title[k] = TRUE;
194 this_curve -> axis_title_font[k] = g_strdup_printf ("Sans 12");
195 }
196 if (this_curve -> err != NULL)
197 {
198 g_free (this_curve -> err);
199 this_curve -> err = NULL;
200 }
201 this_curve -> labels_shift_x[0] = 10;
202 this_curve -> labels_shift_y[0] = 20;
203 this_curve -> labels_shift_x[1] = 50;
204 this_curve -> labels_shift_y[1] = 10;
205 this_curve -> axis_title_x[0] = -20;
206 this_curve -> axis_title_y[0] = 45;
207 this_curve -> axis_title_x[1] = MARGX - 10;
208 this_curve -> axis_title_y[1] = -50;
209 this_curve -> frame_type = 2;
210 this_curve -> frame_dash = 1;
211 this_curve -> frame_thickness = 1.0;
212 this_curve -> frame_color.red = 0.0;
213 this_curve -> frame_color.green = 0.0;
214 this_curve -> frame_color.blue = 0.0;
215 this_curve -> frame_color.alpha = 1.0;
216 this_curve -> frame_pos[0][0] = 100.0/840.0;
217 this_curve -> frame_pos[0][1] = 1.0;
218 this_curve -> frame_pos[1][0] = 530.0/600.0;
219 this_curve -> frame_pos[1][1] = 0.0;
220 this_curve -> legend_font = g_strdup_printf ("Sans 10");
221 this_curve -> show_legend = FALSE;
222 this_curve -> show_frame = TRUE;
223 this_curve -> legend_color.red = 0.0;
224 this_curve -> legend_color.blue = 0.0;
225 this_curve -> legend_color.green = 0.0;
226 this_curve -> legend_color.alpha = 1.0;
227 this_curve -> legend_pos[0] = LEGX;
228 this_curve -> legend_pos[1] = LEGY;
229 this_curve -> show_legend_box = FALSE;
230 this_curve -> legend_box_dash = 1;
231 this_curve -> legend_box_color.red = 0.0;
232 this_curve -> legend_box_color.green = 0.0;
233 this_curve -> legend_box_color.blue = 0.0;
234 this_curve -> legend_box_color.alpha = 1.0;
235 this_curve -> legend_box_thickness = 1.0;
236 this_curve -> backcolor.red = 1.0;
237 this_curve -> backcolor.green = 1.0;
238 this_curve -> backcolor.blue = 1.0;
239 this_curve -> backcolor.alpha = 1.0;
240 this_curve -> layout = curve_default_layout (pid, rid, cid);
241 this_curve -> extrac = NULL;
242 this_curve -> extrac = g_malloc0(sizeof*this_curve -> extrac);
243 this_curve -> extrac -> extras = 0;
244 if (this_curve -> cfile != NULL)
245 {
246 g_free (this_curve -> cfile);
247 }
248 curve_default_scale (pid, rid, cid, this_curve);
249}
250
260void init_curve_title (project * this_proj, int rid, int cid)
261{
262 if (this_proj -> analysis[rid] -> curves[cid] -> default_title)
263 {
264 this_proj -> analysis[rid] -> curves[cid] -> title = g_strdup_printf ("%s - %s", prepare_for_title(this_proj -> name), this_proj -> analysis[rid] -> curves[cid] -> name);
265 }
266 int i;
267 for (i=0; i<2; i++)
268 {
269 if (this_proj -> analysis[rid] -> curves[cid] -> axis_defaut_title[i])
270 {
271 this_proj -> analysis[rid] -> curves[cid] -> axis_title[i] = g_strdup_printf ("%s", default_title(i, & this_proj -> analysis[rid] -> idcc[cid]));
272 }
273 }
274}
275
283void add_curve_widgets (project * this_proj, int rid)
284{
285 int i;
286 for (i=0; i<this_proj -> analysis[rid] -> numc; i++)
287 {
288 this_proj -> analysis[rid] -> curves[i] -> cid = i;
289 if (this_proj -> analysis[rid] -> curves[i] -> ndata == 0)
290 {
291 initcurve (this_proj, rid, i);
292 }
293 if (this_proj -> analysis[rid] -> curves[i] -> name)
294 {
295 init_curve_title (this_proj, rid, i);
296 }
297 }
298}
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:205
PangoLayout * layout
Definition curve.c:80
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 show_title(cairo_t *cr, Curve *this_curve)
draw title
Definition title.c:104
#define MARGX
Definition curve.h:54
#define DTHICK
Definition curve.h:48
void show_legend(cairo_t *cr, project *this_proj, int rid, int cid)
draw legend
Definition legend.c:56
#define BLUE
Definition curve.h:46
#define LEGX
Definition curve.h:41
#define LEGY
Definition curve.h:42
#define RED
Definition curve.h:44
const gchar * default_title(int ax, gpointer data)
default title string
Definition title.c:54
#define GREEN
Definition curve.h:45
void add_curve_widgets(project *this_proj, int rid)
add curve widgets to the project
Definition cwidget.c:283
DataLayout * curve_default_layout(project *pid, int rid, int cid)
prepare the default layout for a curve
Definition cwidget.c:58
void initcurve(project *pid, int rid, int cid)
initialize curve widget
Definition cwidget.c:159
void init_curve_title(project *this_proj, int rid, int cid)
init curve title and axis titles
Definition cwidget.c:260
void curve_default_scale(project *this_proj, int rid, int cid, Curve *this_curve)
pick appropriate scale based on the type of analysis
Definition cwidget.c:117
Global variable declarations Global convenience function declarations Global data structure defin...
#define SKT
Definition global.h:347
#define RIN
Definition global.h:343
#define SPH
Definition global.h:345
#define min(a, b)
Definition global.h:93
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
#define MSD
Definition global.h:346
#define max(a, b)
Definition global.h:92
image * plot
Definition ogl_draw.c:72
Messaging function declarations.
void autoscale(gpointer data)
autoscale callback
Definition m_curve.c:99