1 /*   EXTRAITS DE LA LICENCE
2 	Copyright CEA, contributeurs : Damien
3 	CALISTE, laboratoire L_Sim, (2017)
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, (2017)
25 
26 	E-mail address:
27 	BILLARD, not reachable any more ;
28 	CALISTE, damien P caliste AT cea P fr.
29 
30 	This software is a computer program whose purpose is to visualize atomic
31 	configurations in 3D.
32 
33 	This software is governed by the CeCILL  license under French law and
34 	abiding by the rules of distribution of free software.  You can  use,
35 	modify and/ or redistribute the software under the terms of the CeCILL
36 	license as circulated by CEA, CNRS and INRIA at the following URL
37 	"http://www.cecill.info".
38 
39 	The fact that you are presently reading this means that you have had
40 	knowledge of the CeCILL license and that you accept its terms. You can
41 	find a copy of this licence shipped with this software at Documentation/licence.en.txt.
42 */
43 #include "iface_nodemasker.h"
44 
45 #include "config.h"
46 
47 /**
48  * SECTION:iface_nodemasker
49  * @short_description: an interface for objects with masking
50  * capabilities on #VisuNode.
51  *
52  * <para>Implementers of this interface are objects that can change
53  * the visibility of #VisuNode through the visu_node_masker_apply()
54  * routine. When an implementer has its masking parameters that have
55  * changed, it should call visu_node_masker_emitDirty().</para>
56  */
57 
58 
59 /* enum { */
60 /*   PROP_0, */
61 /*   N_PROPS */
62 /* }; */
63 /* static GParamSpec *properties[N_PROPS]; */
64 
65 enum
66   {
67     DIRTY_SIGNAL,
68     NB_SIGNAL
69   };
70 static guint _signals[NB_SIGNAL] = { 0 };
71 
72 /* NodeMasker interface. */
G_DEFINE_INTERFACE(VisuNodeMasker,visu_node_masker,G_TYPE_OBJECT)73 G_DEFINE_INTERFACE(VisuNodeMasker, visu_node_masker, G_TYPE_OBJECT)
74 
75 static void visu_node_masker_default_init(VisuNodeMaskerInterface *iface)
76 {
77   /**
78    * VisuNodeMasker::masking-dirty:
79    * @masker: the object emitting the signal.
80    *
81    * This signal is emitted when some masking parameters changed.
82    *
83    * Since: 3.8
84    */
85   _signals[DIRTY_SIGNAL] =
86     g_signal_new("masking-dirty", G_TYPE_FROM_INTERFACE(iface),
87                  G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
88                  0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
89                  G_TYPE_NONE, 0, NULL);
90 }
91 
92 /**
93  * visu_node_masker_setMaskFunc:
94  * @masker: a #VisuNodeMasker object.
95  * @func: (closure data) (scope notified) (allow-none): a #VisuNodeMaskerFunc object.
96  * @data: (closure): some data.
97  * @destroy: (destroy data): destroy function.
98  *
99  * If the implementation provides a user defined masking function,
100  * this calls the #VisuNodeMaskerInterface::set_mask_func() routine.
101  *
102  * Since: 3.8
103  *
104  * Returns: TRUE if value is actually changed.
105  **/
visu_node_masker_setMaskFunc(VisuNodeMasker * masker,VisuNodeMaskerFunc func,gpointer data,GDestroyNotify destroy)106 gboolean visu_node_masker_setMaskFunc(VisuNodeMasker *masker, VisuNodeMaskerFunc func,
107                                       gpointer data, GDestroyNotify destroy)
108 {
109   gboolean res;
110 
111   g_return_val_if_fail(VISU_IS_NODE_MASKER(masker), FALSE);
112 
113   if (!VISU_NODE_MASKER_GET_INTERFACE(masker)->set_mask_func)
114     return FALSE;
115 
116   res = VISU_NODE_MASKER_GET_INTERFACE(masker)->set_mask_func(masker, func, data, destroy);
117   if (res)
118     visu_node_masker_emitDirty(masker);
119 
120   return res;
121 }
122 
123 /**
124  * visu_node_masker_apply:
125  * @masker: a #VisuNodeMasker object.
126  * @redraw: (out caller-allocates): a location for a boolean
127  * @array: a #VisuNodeArray object.
128  *
129  * Apply the masking properties of @masker over @array. If any node
130  * visibility has changed, @redraw is set to %TRUE.
131  *
132  * Since: 3.8
133  **/
visu_node_masker_apply(const VisuNodeMasker * masker,gboolean * redraw,VisuNodeArray * array)134 void visu_node_masker_apply(const VisuNodeMasker *masker,
135                             gboolean *redraw, VisuNodeArray *array)
136 {
137   g_return_if_fail(VISU_IS_NODE_MASKER(masker));
138 
139   if (!VISU_NODE_MASKER_GET_INTERFACE(masker)->apply)
140     return;
141 
142   if (VISU_NODE_MASKER_GET_INTERFACE(masker)->apply(masker, array) && redraw)
143     *redraw = TRUE;
144 }
145 
146 /**
147  * visu_node_masker_emitDirty:
148  * @masker: a #VisuNodeMasker object.
149  *
150  * Emits the "masking-dirty" signal. To be used by implementation of
151  * this interface to signal that some masking properties have changed.
152  *
153  * Since: 3.8
154  **/
visu_node_masker_emitDirty(VisuNodeMasker * masker)155 void visu_node_masker_emitDirty(VisuNodeMasker *masker)
156 {
157   DBG_fprintf(stderr, "Visu Node Masker: emitting dirty signal for %p.\n",
158               (gpointer)masker);
159   g_signal_emit(masker, _signals[DIRTY_SIGNAL], 0);
160 }
161