atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_data.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: 'w_data.c'
24*
25* Contains:
26*
27
28 - The functions to export curve data
29
30*
31* List of functions:
32
33 void write_curve (gpointer idata);
34
35 G_MODULE_EXPORT void run_write_curve (GtkNativeDialog * info, gint response_id, gpointer data);
36 G_MODULE_EXPORT void run_write_curve (GtkDialog * info, gint response_id, gpointer data);
37
38*/
39
40#include <gtk/gtk.h>
41#include <string.h>
42#include <stdlib.h>
43
44#include "global.h"
45#include "interface.h"
46#include "curve.h"
47
48void save_to_file_ (int *, char *, int *, double *, double *, int *, int *, int *, double *, int *, int *, int *, int *, char *);
49void prep_file_ (int *, char *, int *, int *, int *, double *, int *, int *);
50void append_to_file_ (int *, double *, double *, double *, int *, int *, int *, int *, int *, int *, int *, char *);
51
52GtkFileFilter * filter1, * filter2;
53
54#ifdef GTK4
64G_MODULE_EXPORT void run_write_curve (GtkNativeDialog * info, gint response_id, gpointer data)
65{
66 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
67#else
77G_MODULE_EXPORT void run_write_curve (GtkDialog * info, gint response_id, gpointer data)
78{
79 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
80#endif
81 int a, b, c, i, j, k, l, m, n, o, p, q;
82 tint * cd = (tint *)data;
83 a = cd -> a;
84 b = cd -> b;
85 c = cd -> c;
86 if (response_id == GTK_RESPONSE_ACCEPT)
87 {
88 project * this_proj = get_project_by_id(a);
89 this_proj -> curves[b][c] -> cfile = file_chooser_get_file_name (chooser);
90 GtkFileFilter * tmp = gtk_file_chooser_get_filter (chooser);
91 if (tmp == filter1)
92 {
93 l = 0;
94 }
95 else if (tmp == filter2)
96 {
97 l = 1;
98 }
99 k = strlen(this_proj -> curves[b][c] -> cfile);
100 j = strlen (this_proj -> curves[b][c] -> title);
101 if (this_proj -> curves[b][c] -> extrac -> extras == 0)
102 {
103 save_to_file_ (& k, this_proj -> curves[b][c] -> cfile,
104 & this_proj -> curves[b][c] -> ndata,
105 this_proj -> curves[b][c] -> data[0],
106 this_proj -> curves[b][c] -> data[1],
107 & this_proj -> curves[b][c] -> scale[0],
108 & this_proj -> curves[b][c] -> scale[1],
109 & this_proj -> curves[b][c] -> layout -> aspect,
110 & this_proj -> delta[b], & b, & c, & l,
111 & j, this_proj -> curves[b][c] -> title);
112
113 }
114 else
115 {
116 p = this_proj -> curves[b][c] -> extrac -> extras + 1;
117 m = 0;
118 prep_file_ (& k, this_proj -> curves[b][c] -> cfile, & l,
119 & this_proj -> curves[b][c] -> scale[0],
120 & this_proj -> curves[b][c] -> scale[1],
121 & this_proj -> delta[b], & b, & c);
122 append_to_file_ (& this_proj -> curves[b][c] -> ndata,
123 this_proj -> curves[b][c] -> data[0],
124 this_proj -> curves[b][c] -> data[1],
125 & this_proj -> delta[b],
126 & this_proj -> curves[b][c] -> layout -> aspect,
127 & b, & c, & l, & m, & p,
128 & j, this_proj -> curves[b][c] -> title);
129 j = this_proj -> curves[b][c] -> extrac -> extras;
130 CurveExtra * ctmp = this_proj -> curves[b][c] -> extrac -> first;
131 for (i=0 ; i < j ; i++ )
132 {
133 m = m + 1;
134 q = ctmp -> id.a;
135 o = ctmp -> id.b;
136 n = ctmp -> id.c;
137 this_proj = get_project_by_id(q);
138 j = strlen (this_proj -> curves[o][n] -> title);
139 append_to_file_ (& this_proj -> curves[o][n] -> ndata,
140 this_proj -> curves[o][n] -> data[0],
141 this_proj -> curves[o][n] -> data[1],
142 & this_proj -> delta[o],
143 & ctmp -> layout -> aspect,
144 & o, & n, & l, & m, & p,
145 & j, this_proj -> curves[o][n] -> title);
146 if (ctmp -> next) ctmp = ctmp -> next;
147 }
148 }
149 }
150#ifdef GTK4
152#else
153 destroy_this_dialog (info);
154#endif
155}
156
164void write_curve (gpointer idata)
165{
166#ifdef GTK4
167 GtkFileChooserNative * info;
168#else
169 GtkWidget * info;
170#endif
171 tint * cd = (tint *)idata;
172 int a, b, c;
173 a = cd -> a;
174 b = cd -> b;
175 c = cd -> c;
176 project * this_proj = get_project_by_id(a);
177 info = create_file_chooser ("Save Data",
178 GTK_WINDOW(this_proj -> curves[b][c] -> window),
179 GTK_FILE_CHOOSER_ACTION_SAVE,
180 "Save");
181 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
182#ifdef GTK3
183 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
184#endif
185 filter1 = gtk_file_filter_new();
186 gtk_file_filter_set_name (GTK_FILE_FILTER(filter1), "Xmgrace file (*.agr)");
187 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter1), "*.agr");
188 gtk_file_chooser_add_filter (chooser, filter1);
189 filter2 = gtk_file_filter_new();
190 gtk_file_filter_set_name (GTK_FILE_FILTER(filter2), "x/y ASCII file (*.dat)");
191 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter2), "*.dat");
192 gtk_file_chooser_add_filter (chooser, filter2);
193 if (this_proj -> curves[b][c] -> cfile != NULL)
194 {
195 if (! file_chooser_set_file_name (chooser, this_proj -> curves[b][c] -> cfile)) goto end;
196 }
197 else
198 {
200 gtk_file_chooser_set_current_name (chooser, this_proj -> curves[b][c] -> name);
201 }
202#ifdef GTK4
203 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_write_curve), idata);
204#else
205 run_this_gtk_dialog (info, G_CALLBACK(run_write_curve), idata);
206#endif
207 end:;
208}
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.
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:492
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2188
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
Definition gtk-misc.c:2136
gboolean file_chooser_set_file_name(GtkFileChooser *chooser, gchar *filename)
set file name in a GtkFilechooser
Definition gtk-misc.c:2169
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
GtkWidget * create_file_chooser(const gchar *title, GtkWindow *parent, GtkFileChooserAction act, const gchar *act_name)
create a GtkFileChooser, utility to select file(s)
Definition gtk-misc.c:2223
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
Definition gtk-misc.c:2084
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
Messaging function declarations.
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
void save_to_file_(int *, char *, int *, double *, double *, int *, int *, int *, double *, int *, int *, int *, int *, char *)
void append_to_file_(int *, double *, double *, double *, int *, int *, int *, int *, int *, int *, int *, char *)
GtkFileFilter * filter1
Definition w_data.c:52
GtkFileFilter * filter2
Definition w_data.c:52
void prep_file_(int *, char *, int *, int *, int *, double *, int *, int *)
G_MODULE_EXPORT void run_write_curve(GtkDialog *info, gint response_id, gpointer data)
save curve data - running the dialog GTK3
Definition w_data.c:77
void write_curve(gpointer idata)
save curve data - creating the dialog
Definition w_data.c:164