1 /*   EXTRAITS DE LA LICENCE
2 	Copyright CEA, contributeurs : Damien
3 	CALISTE, laboratoire L_Sim, (2016)
4 
5 	Adresse mèl :
6 	CALISTE, damien P caliste AT cea P fr.
7 
8 	Ce logiciel est un programme informatique servant à visualiser des
9 	structures atomiques dans un rendu pseudo-3D.
10 
11 	Ce logiciel est régi par la licence CeCILL soumise au droit français et
12 	respectant les principes de diffusion des logiciels libres. Vous pouvez
13 	utiliser, modifier et/ou redistribuer ce programme sous les conditions
14 	de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
15 	sur le site "http://www.cecill.info".
16 
17 	Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
18 	pris connaissance de la licence CeCILL, et que vous en avez accepté les
19 	termes (cf. le fichier Documentation/licence.fr.txt fourni avec ce logiciel).
20 */
21 
22 /*   LICENCE SUM UP
23 	Copyright CEA, contributors : Damien
24 	CALISTE, laboratoire L_Sim, (2016)
25 
26 	E-mail address:
27 	CALISTE, damien P caliste AT cea P fr.
28 
29 	This software is a computer program whose purpose is to visualize atomic
30 	configurations in 3D.
31 
32 	This software is governed by the CeCILL  license under French law and
33 	abiding by the rules of distribution of free software.  You can  use,
34 	modify and/ or redistribute the software under the terms of the CeCILL
35 	license as circulated by CEA, CNRS and INRIA at the following URL
36 	"http://www.cecill.info".
37 
38 	The fact that you are presently reading this means that you have had
39 	knowledge of the CeCILL license and that you accept its terms. You can
40 	find a copy of this licence shipped with this software at Documentation/licence.en.txt.
41 */
42 
43 #include "fileDump.h"
44 
45 /**
46  * SECTION:fileDump
47  * @short_description: A generic class defining interface to export
48  * #VisuData into text formats.
49  *
50  * <para>Instance of this class can be used to export any #VisuData
51  * into other text formats.</para>
52  */
53 
54 struct _VisuDumpDataPrivate
55 {
56   VisuDumpDataWriteFunc writeFunc;
57 };
58 
59 /* Local callbacks */
60 
G_DEFINE_TYPE_WITH_CODE(VisuDumpData,visu_dump_data,VISU_TYPE_DUMP,G_ADD_PRIVATE (VisuDumpData))61 G_DEFINE_TYPE_WITH_CODE(VisuDumpData, visu_dump_data, VISU_TYPE_DUMP,
62                         G_ADD_PRIVATE(VisuDumpData))
63 
64 static void visu_dump_data_class_init(VisuDumpDataClass *klass _U_)
65 {
66   DBG_fprintf(stderr, "Visu Node Scene: creating the class of the object.\n");
67   /* DBG_fprintf(stderr, "                - adding new signals ;\n"); */
68 }
69 
visu_dump_data_init(VisuDumpData * self)70 static void visu_dump_data_init(VisuDumpData *self)
71 {
72   self->priv = visu_dump_data_get_instance_private(self);
73   self->priv->writeFunc = NULL;
74 }
75 
76 /**
77  * visu_dump_data_new:
78  * @descr: a description.
79  * @patterns: (array zero-terminated=1): a list of file patterns.
80  * @method: (scope call): the write method.
81  *
82  * Creates a new #VisuDumpData object.
83  *
84  * Since: 3.8
85  *
86  * Returns: (transfer full): a newly created #VisuDumpData object.
87  **/
visu_dump_data_new(const gchar * descr,const gchar ** patterns,VisuDumpDataWriteFunc method)88 VisuDumpData* visu_dump_data_new(const gchar* descr, const gchar** patterns,
89                                  VisuDumpDataWriteFunc method)
90 {
91   VisuDumpData *dump;
92 
93   dump = VISU_DUMP_DATA(g_object_new(VISU_TYPE_DUMP_DATA,
94                                      "name", descr, "ignore-type", FALSE, NULL));
95   tool_file_format_addPatterns(TOOL_FILE_FORMAT(dump), patterns);
96   dump->priv->writeFunc = method;
97 
98   return dump;
99 }
100 
101 /**
102  * visu_dump_data_write:
103  * @dump: a #VisuDump object ;
104  * @fileName: (type filename): a string that defined the file to write to ;
105  * @dataObj: the #VisuData to be exported ;
106  * @error: a location to store some error (not NULL) ;
107  *
108  * Use the write function of @dump to export the current @dataObj to
109  * file @fileName.
110  *
111  * Since: 3.6
112  *
113  * Returns: TRUE if dump succeed.
114  */
visu_dump_data_write(VisuDumpData * dump,const char * fileName,VisuData * dataObj,GError ** error)115 gboolean visu_dump_data_write(VisuDumpData *dump, const char* fileName,
116                               VisuData *dataObj, GError **error)
117 {
118   g_return_val_if_fail(VISU_IS_DUMP_DATA(dump) && dump->priv->writeFunc, FALSE);
119 
120   return dump->priv->writeFunc(dump, fileName, dataObj, error);
121 }
122