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