~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/node_socket.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version. 
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * The Original Code is Copyright (C) 2007 Blender Foundation.
 
19
 * All rights reserved.
 
20
 *
 
21
 * The Original Code is: all of this file.
 
22
 *
 
23
 * Contributor(s): Lukas Toennne
 
24
 *
 
25
 * ***** END GPL LICENSE BLOCK *****
 
26
 */
 
27
 
 
28
/** \file blender/nodes/intern/node_socket.c
 
29
 *  \ingroup nodes
 
30
 */
 
31
 
 
32
#include <limits.h>
 
33
 
 
34
#include "DNA_node_types.h"
 
35
 
 
36
#include "DNA_mesh_types.h"
 
37
#include "DNA_meshdata_types.h"
 
38
#include "DNA_object_types.h"
 
39
#include "DNA_scene_types.h"
 
40
 
 
41
#include "BLI_listbase.h"
 
42
#include "BLI_math.h"
 
43
#include "BLI_utildefines.h"
 
44
 
 
45
#include "BKE_DerivedMesh.h"
 
46
#include "BKE_node.h"
 
47
 
 
48
#include "RNA_access.h"
 
49
#include "RNA_types.h"
 
50
 
 
51
#include "MEM_guardedalloc.h"
 
52
 
 
53
#include "NOD_socket.h"
 
54
 
 
55
/****************** FLOAT ******************/
 
56
 
 
57
static bNodeSocketType node_socket_type_float = {
 
58
        /* type */                              SOCK_FLOAT,
 
59
        /* ui_name */                   "Float",
 
60
        /* ui_description */    "Floating Point",
 
61
        /* ui_icon */                   0,
 
62
        /* ui_color */                  {160,160,160,255},
 
63
 
 
64
        /* value_structname */  "bNodeSocketValueFloat",
 
65
        /* value_structsize */  sizeof(bNodeSocketValueFloat),
 
66
 
 
67
        /* buttonfunc */                NULL,
 
68
};
 
69
 
 
70
/****************** VECTOR ******************/
 
71
 
 
72
static bNodeSocketType node_socket_type_vector = {
 
73
        /* type */                              SOCK_VECTOR,
 
74
        /* ui_name */                   "Vector",
 
75
        /* ui_description */    "3-dimensional floating point vector",
 
76
        /* ui_icon */                   0,
 
77
        /* ui_color */                  {100,100,200,255},
 
78
 
 
79
        /* value_structname */  "bNodeSocketValueVector",
 
80
        /* value_structsize */  sizeof(bNodeSocketValueVector),
 
81
 
 
82
        /* buttonfunc */                NULL,
 
83
};
 
84
 
 
85
/****************** RGBA ******************/
 
86
 
 
87
static bNodeSocketType node_socket_type_rgba = {
 
88
        /* type */                              SOCK_RGBA,
 
89
        /* ui_name */                   "RGBA",
 
90
        /* ui_description */    "RGBA color",
 
91
        /* ui_icon */                   0,
 
92
        /* ui_color */                  {200,200,40,255},
 
93
 
 
94
        /* value_structname */  "bNodeSocketValueRGBA",
 
95
        /* value_structsize */  sizeof(bNodeSocketValueRGBA),
 
96
 
 
97
        /* buttonfunc */                NULL,
 
98
};
 
99
 
 
100
/****************** INT ******************/
 
101
 
 
102
static bNodeSocketType node_socket_type_int = {
 
103
        /* type */                              SOCK_INT,
 
104
        /* ui_name */                   "Int",
 
105
        /* ui_description */    "Integer",
 
106
        /* ui_icon */                   0,
 
107
        /* ui_color */                  {17,133,37,255},
 
108
 
 
109
        /* value_structname */  "bNodeSocketValueInt",
 
110
        /* value_structsize */  sizeof(bNodeSocketValueInt),
 
111
 
 
112
        /* buttonfunc */                NULL,
 
113
};
 
114
 
 
115
/****************** BOOLEAN ******************/
 
116
 
 
117
static bNodeSocketType node_socket_type_boolean = {
 
118
        /* type */                              SOCK_BOOLEAN,
 
119
        /* ui_name */                   "Boolean",
 
120
        /* ui_description */    "Boolean",
 
121
        /* ui_icon */                   0,
 
122
        /* ui_color */                  {158,139,63,255},
 
123
 
 
124
        /* value_structname */  "bNodeSocketValueBoolean",
 
125
        /* value_structsize */  sizeof(bNodeSocketValueBoolean),
 
126
 
 
127
        /* buttonfunc */                NULL,
 
128
};
 
129
 
 
130
/****************** SHADER ******************/
 
131
 
 
132
static bNodeSocketType node_socket_type_shader = {
 
133
        /* type */                              SOCK_SHADER,
 
134
        /* ui_name */                   "Shader",
 
135
        /* ui_description */    "Shader",
 
136
        /* ui_icon */                   0,
 
137
        /* ui_color */                  {100,200,100,255},
 
138
 
 
139
        /* value_structname */  NULL,
 
140
        /* value_structsize */  0,
 
141
 
 
142
        /* buttonfunc */                NULL,
 
143
};
 
144
 
 
145
/****************** MESH ******************/
 
146
 
 
147
static bNodeSocketType node_socket_type_mesh = {
 
148
        /* type */                              SOCK_MESH,
 
149
        /* ui_name */                   "Mesh",
 
150
        /* ui_description */    "Mesh geometry data",
 
151
        /* ui_icon */                   0,
 
152
        /* ui_color */                  {255,133,7,255},
 
153
 
 
154
        /* value_structname */  NULL,
 
155
        /* value_structsize */  0,
 
156
 
 
157
        /* buttonfunc */                NULL,
 
158
};
 
159
 
 
160
 
 
161
void node_socket_type_init(bNodeSocketType *types[])
 
162
{
 
163
        #define INIT_TYPE(name)         types[node_socket_type_##name.type] = &node_socket_type_##name
 
164
        
 
165
        INIT_TYPE(float);
 
166
        INIT_TYPE(vector);
 
167
        INIT_TYPE(rgba);
 
168
        INIT_TYPE(int);
 
169
        INIT_TYPE(boolean);
 
170
        INIT_TYPE(shader);
 
171
        INIT_TYPE(mesh);
 
172
        
 
173
        #undef INIT_TYPE
 
174
}
 
175
 
 
176
void *node_socket_make_default_value(int type)
 
177
{
 
178
        /* XXX currently just allocates from stype->structsize.
 
179
         * it might become necessary to do more complex allocations for later types.
 
180
         */
 
181
        bNodeSocketType *stype = ntreeGetSocketType(type);
 
182
        if (stype->value_structsize > 0) {
 
183
                void *default_value = MEM_callocN(stype->value_structsize, "default socket value");
 
184
                return default_value;
 
185
        }
 
186
        else
 
187
                return NULL;
 
188
}
 
189
 
 
190
void node_socket_free_default_value(int UNUSED(type), void *default_value)
 
191
{
 
192
        /* XXX can just free the pointee for all current socket types. */
 
193
        if (default_value)
 
194
                MEM_freeN(default_value);
 
195
}
 
196
 
 
197
void node_socket_init_default_value(int type, void *default_value)
 
198
{
 
199
        switch (type) {
 
200
        case SOCK_FLOAT:
 
201
                node_socket_set_default_value_float(default_value, PROP_NONE, 0.0f, -FLT_MAX, FLT_MAX);
 
202
                break;
 
203
        case SOCK_INT:
 
204
                node_socket_set_default_value_int(default_value, PROP_NONE, 0, INT_MIN, INT_MAX);
 
205
                break;
 
206
        case SOCK_BOOLEAN:
 
207
                node_socket_set_default_value_boolean(default_value, FALSE);
 
208
                break;
 
209
        case SOCK_VECTOR:
 
210
                node_socket_set_default_value_vector(default_value, PROP_NONE, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX);
 
211
                break;
 
212
        case SOCK_RGBA:
 
213
                node_socket_set_default_value_rgba(default_value, 0.0f, 0.0f, 0.0f, 1.0f);
 
214
                break;
 
215
        case SOCK_SHADER:
 
216
                node_socket_set_default_value_shader(default_value);
 
217
                break;
 
218
        case SOCK_MESH:
 
219
                node_socket_set_default_value_mesh(default_value);
 
220
                break;
 
221
        }
 
222
}
 
223
 
 
224
void node_socket_set_default_value_int(void *default_value, PropertySubType subtype, int value, int min, int max)
 
225
{
 
226
        bNodeSocketValueInt *val = default_value;
 
227
        val->subtype = subtype;
 
228
        val->value = value;
 
229
        val->min = min;
 
230
        val->max = max;
 
231
}
 
232
 
 
233
void node_socket_set_default_value_float(void *default_value, PropertySubType subtype, float value, float min, float max)
 
234
{
 
235
        bNodeSocketValueFloat *val = default_value;
 
236
        val->subtype = subtype;
 
237
        val->value = value;
 
238
        val->min = min;
 
239
        val->max = max;
 
240
}
 
241
 
 
242
void node_socket_set_default_value_boolean(void *default_value, char value)
 
243
{
 
244
        bNodeSocketValueBoolean *val = default_value;
 
245
        val->value = value;
 
246
}
 
247
 
 
248
void node_socket_set_default_value_vector(void *default_value, PropertySubType subtype, float x, float y, float z, float min, float max)
 
249
{
 
250
        bNodeSocketValueVector *val = default_value;
 
251
        val->subtype = subtype;
 
252
        val->value[0] = x;
 
253
        val->value[1] = y;
 
254
        val->value[2] = z;
 
255
        val->min = min;
 
256
        val->max = max;
 
257
}
 
258
 
 
259
void node_socket_set_default_value_rgba(void *default_value, float r, float g, float b, float a)
 
260
{
 
261
        bNodeSocketValueRGBA *val = default_value;
 
262
        val->value[0] = r;
 
263
        val->value[1] = g;
 
264
        val->value[2] = b;
 
265
        val->value[3] = a;
 
266
}
 
267
 
 
268
void node_socket_set_default_value_shader(void *UNUSED(default_value))
 
269
{
 
270
}
 
271
 
 
272
void node_socket_set_default_value_mesh(void *UNUSED(default_value))
 
273
{
 
274
}
 
275
 
 
276
 
 
277
void node_socket_copy_default_value(int type, void *to_default_value, void *from_default_value)
 
278
{
 
279
        /* XXX only one of these pointers is valid! just putting them here for convenience */
 
280
        bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from_default_value;
 
281
        bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from_default_value;
 
282
        bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from_default_value;
 
283
        bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from_default_value;
 
284
        bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from_default_value;
 
285
 
 
286
        bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to_default_value;
 
287
        bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to_default_value;
 
288
        bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to_default_value;
 
289
        bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to_default_value;
 
290
        bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to_default_value;
 
291
 
 
292
        switch (type) {
 
293
        case SOCK_FLOAT:
 
294
                *tofloat = *fromfloat;
 
295
                break;
 
296
        case SOCK_INT:
 
297
                *toint = *fromint;
 
298
                break;
 
299
        case SOCK_BOOLEAN:
 
300
                *tobool = *frombool;
 
301
                break;
 
302
        case SOCK_VECTOR:
 
303
                *tovector = *fromvector;
 
304
                break;
 
305
        case SOCK_RGBA:
 
306
                *torgba = *fromrgba;
 
307
                break;
 
308
        }
 
309
}
 
310
 
 
311
/* XXX This is a makeshift function to have useful initial group socket values.
 
312
 * In the end this should be implemented by a flexible socket data conversion system,
 
313
 * which is yet to be implemented. The idea is that beside default standard conversions,
 
314
 * such as int-to-float, it should be possible to quickly select a conversion method or
 
315
 * a chain of conversions for each input, whenever there is more than one option.
 
316
 * E.g. a vector-to-float conversion could use either of the x/y/z components or
 
317
 * the vector length.
 
318
 *
 
319
 * In the interface this could be implemented by a pseudo-script textbox on linked inputs,
 
320
 * with quick selection from a predefined list of conversion options. Some Examples:
 
321
 * - vector component 'z' (vector->float):                                              "z"
 
322
 * - greyscale color (float->color):                                                    "grey"
 
323
 * - color luminance (color->float):                                                    "lum"
 
324
 * - matrix column 2 length (matrix->vector->float):                    "col[1].len"
 
325
 * - mesh vertex coordinate 'y' (mesh->vertex->vector->float):  "vertex.co.y"
 
326
 *
 
327
 * The actual conversion is then done by a series of conversion functions,
 
328
 * which are defined in the socket type structs.
 
329
 */
 
330
void node_socket_convert_default_value(int to_type, void *to_default_value, int from_type, void *from_default_value)
 
331
{
 
332
        /* XXX only one of these pointers is valid! just putting them here for convenience */
 
333
        bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from_default_value;
 
334
        bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from_default_value;
 
335
        bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from_default_value;
 
336
        bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from_default_value;
 
337
        bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from_default_value;
 
338
 
 
339
        bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to_default_value;
 
340
        bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to_default_value;
 
341
        bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to_default_value;
 
342
        bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to_default_value;
 
343
        bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to_default_value;
 
344
 
 
345
        switch (from_type) {
 
346
        case SOCK_FLOAT:
 
347
                switch (to_type) {
 
348
                case SOCK_FLOAT:
 
349
                        tofloat->value = fromfloat->value;
 
350
                        break;
 
351
                case SOCK_INT:
 
352
                        toint->value = (int)fromfloat->value;
 
353
                        break;
 
354
                case SOCK_BOOLEAN:
 
355
                        tobool->value = (fromfloat->value > 0.0f);
 
356
                        break;
 
357
                case SOCK_VECTOR:
 
358
                        tovector->value[0] = tovector->value[1] = tovector->value[2] = fromfloat->value;
 
359
                        break;
 
360
                case SOCK_RGBA:
 
361
                        torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = fromfloat->value;
 
362
                        break;
 
363
                }
 
364
                break;
 
365
        case SOCK_INT:
 
366
                switch (to_type) {
 
367
                case SOCK_FLOAT:
 
368
                        tofloat->value = (float)fromint->value;
 
369
                        break;
 
370
                case SOCK_INT:
 
371
                        toint->value = fromint->value;
 
372
                        break;
 
373
                case SOCK_BOOLEAN:
 
374
                        tobool->value = (fromint->value > 0);
 
375
                        break;
 
376
                case SOCK_VECTOR:
 
377
                        tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)fromint->value;
 
378
                        break;
 
379
                case SOCK_RGBA:
 
380
                        torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)fromint->value;
 
381
                        break;
 
382
                }
 
383
                break;
 
384
        case SOCK_BOOLEAN:
 
385
                switch (to_type) {
 
386
                case SOCK_FLOAT:
 
387
                        tofloat->value = (float)frombool->value;
 
388
                        break;
 
389
                case SOCK_INT:
 
390
                        toint->value = (int)frombool->value;
 
391
                        break;
 
392
                case SOCK_BOOLEAN:
 
393
                        tobool->value = frombool->value;
 
394
                        break;
 
395
                case SOCK_VECTOR:
 
396
                        tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)frombool->value;
 
397
                        break;
 
398
                case SOCK_RGBA:
 
399
                        torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)frombool->value;
 
400
                        break;
 
401
                }
 
402
                break;
 
403
        case SOCK_VECTOR:
 
404
                switch (to_type) {
 
405
                case SOCK_FLOAT:
 
406
                        tofloat->value = fromvector->value[0];
 
407
                        break;
 
408
                case SOCK_INT:
 
409
                        toint->value = (int)fromvector->value[0];
 
410
                        break;
 
411
                case SOCK_BOOLEAN:
 
412
                        tobool->value = (fromvector->value[0] > 0.0f);
 
413
                        break;
 
414
                case SOCK_VECTOR:
 
415
                        copy_v3_v3(tovector->value, fromvector->value);
 
416
                        break;
 
417
                case SOCK_RGBA:
 
418
                        copy_v3_v3(torgba->value, fromvector->value);
 
419
                        torgba->value[3] = 1.0f;
 
420
                        break;
 
421
                }
 
422
                break;
 
423
        case SOCK_RGBA:
 
424
                switch (to_type) {
 
425
                case SOCK_FLOAT:
 
426
                        tofloat->value = fromrgba->value[0];
 
427
                        break;
 
428
                case SOCK_INT:
 
429
                        toint->value = (int)fromrgba->value[0];
 
430
                        break;
 
431
                case SOCK_BOOLEAN:
 
432
                        tobool->value = (fromrgba->value[0] > 0.0f);
 
433
                        break;
 
434
                case SOCK_VECTOR:
 
435
                        copy_v3_v3(tovector->value, fromrgba->value);
 
436
                        break;
 
437
                case SOCK_RGBA:
 
438
                        copy_v4_v4(torgba->value, fromrgba->value);
 
439
                        break;
 
440
                }
 
441
                break;
 
442
        }
 
443
}
 
444
 
 
445
 
 
446
struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
 
447
{
 
448
        bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_IN, stemp->name, stemp->type);
 
449
        sock->flag |= stemp->flag;
 
450
        
 
451
        switch (stemp->type) {
 
452
        case SOCK_INT:
 
453
                node_socket_set_default_value_int(sock->default_value, stemp->subtype, (int)stemp->val1, (int)stemp->min, (int)stemp->max);
 
454
                break;
 
455
        case SOCK_FLOAT:
 
456
                node_socket_set_default_value_float(sock->default_value, stemp->subtype, stemp->val1, stemp->min, stemp->max);
 
457
                break;
 
458
        case SOCK_BOOLEAN:
 
459
                node_socket_set_default_value_boolean(sock->default_value, (char)stemp->val1);
 
460
                break;
 
461
        case SOCK_VECTOR:
 
462
                node_socket_set_default_value_vector(sock->default_value, stemp->subtype, stemp->val1, stemp->val2, stemp->val3, stemp->min, stemp->max);
 
463
                break;
 
464
        case SOCK_RGBA:
 
465
                node_socket_set_default_value_rgba(sock->default_value, stemp->val1, stemp->val2, stemp->val3, stemp->val4);
 
466
                break;
 
467
        case SOCK_SHADER:
 
468
                node_socket_set_default_value_shader(sock->default_value);
 
469
                break;
 
470
        case SOCK_MESH:
 
471
                node_socket_set_default_value_mesh(sock->default_value);
 
472
                break;
 
473
        }
 
474
        
 
475
        return sock;
 
476
}
 
477
 
 
478
struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
 
479
{
 
480
        bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_OUT, stemp->name, stemp->type);
 
481
        return sock;
 
482
}
 
483
 
 
484
static bNodeSocket *verify_socket_template(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp)
 
485
{
 
486
        bNodeSocket *sock;
 
487
        
 
488
        for (sock= socklist->first; sock; sock= sock->next) {
 
489
                if (!(sock->flag & SOCK_DYNAMIC) && strncmp(sock->name, stemp->name, NODE_MAXSTR)==0)
 
490
                        break;
 
491
        }
 
492
        if (sock) {
 
493
                sock->type= stemp->type;                /* in future, read this from tydefs! */
 
494
                if (stemp->limit==0) sock->limit= 0xFFF;
 
495
                else sock->limit= stemp->limit;
 
496
                sock->flag |= stemp->flag;
 
497
                
 
498
                /* Copy the property range and subtype parameters in case the template changed.
 
499
                 * NOT copying the actual value here, only button behavior changes!
 
500
                 */
 
501
                switch (sock->type) {
 
502
                case SOCK_FLOAT:
 
503
                        {
 
504
                                bNodeSocketValueFloat *dval= sock->default_value;
 
505
                                dval->min = stemp->min;
 
506
                                dval->max = stemp->max;
 
507
                                dval->subtype = stemp->subtype;
 
508
                        }
 
509
                        break;
 
510
                case SOCK_INT:
 
511
                        {
 
512
                                bNodeSocketValueInt *dval= sock->default_value;
 
513
                                dval->min = stemp->min;
 
514
                                dval->max = stemp->max;
 
515
                                dval->subtype = stemp->subtype;
 
516
                        }
 
517
                        break;
 
518
                case SOCK_VECTOR:
 
519
                        {
 
520
                                bNodeSocketValueVector *dval= sock->default_value;
 
521
                                dval->min = stemp->min;
 
522
                                dval->max = stemp->max;
 
523
                                dval->subtype = stemp->subtype;
 
524
                        }
 
525
                        break;
 
526
                }
 
527
                
 
528
                BLI_remlink(socklist, sock);
 
529
                
 
530
                return sock;
 
531
        }
 
532
        else {
 
533
                /* no socket for this template found, make a new one */
 
534
                if (in_out==SOCK_IN)
 
535
                        sock = node_add_input_from_template(ntree, node, stemp);
 
536
                else
 
537
                        sock = node_add_output_from_template(ntree, node, stemp);
 
538
                /* remove the new socket from the node socket list first,
 
539
                 * will be added back after verification.
 
540
                 */
 
541
                BLI_remlink(socklist, sock);
 
542
        }
 
543
        
 
544
        return sock;
 
545
}
 
546
 
 
547
static void verify_socket_template_list(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp_first)
 
548
{
 
549
        bNodeSocket *sock, *nextsock;
 
550
        bNodeSocketTemplate *stemp;
 
551
        
 
552
        /* no inputs anymore? */
 
553
        if (stemp_first==NULL) {
 
554
                for (sock = (bNodeSocket*)socklist->first; sock; sock=nextsock) {
 
555
                        nextsock = sock->next;
 
556
                        if (!(sock->flag & SOCK_DYNAMIC))
 
557
                                nodeRemoveSocket(ntree, node, sock);
 
558
                }
 
559
        }
 
560
        else {
 
561
                /* step by step compare */
 
562
                stemp= stemp_first;
 
563
                while (stemp->type != -1) {
 
564
                        stemp->sock= verify_socket_template(ntree, node, in_out, socklist, stemp);
 
565
                        stemp++;
 
566
                }
 
567
                /* leftovers are removed */
 
568
                for (sock = (bNodeSocket*)socklist->first; sock; sock=nextsock) {
 
569
                        nextsock = sock->next;
 
570
                        if (!(sock->flag & SOCK_DYNAMIC))
 
571
                                nodeRemoveSocket(ntree, node, sock);
 
572
                }
 
573
                
 
574
                /* and we put back the verified sockets */
 
575
                stemp= stemp_first;
 
576
                if (socklist->first) {
 
577
                        /* some dynamic sockets left, store the list start
 
578
                         * so we can add static sockets infront of it.
 
579
                         */
 
580
                        sock = socklist->first;
 
581
                        while (stemp->type != -1) {
 
582
                                /* put static sockets infront of dynamic */
 
583
                                BLI_insertlinkbefore(socklist, sock, stemp->sock);
 
584
                                stemp++;
 
585
                        }
 
586
                }
 
587
                else {
 
588
                        while (stemp->type != -1) {
 
589
                                BLI_addtail(socklist, stemp->sock);
 
590
                                stemp++;
 
591
                        }
 
592
                }
 
593
        }
 
594
}
 
595
 
 
596
void node_verify_socket_templates(bNodeTree *ntree, bNode *node)
 
597
{
 
598
        bNodeType *ntype= node->typeinfo;
 
599
        /* XXX Small trick: don't try to match socket lists when there are no templates.
 
600
         * This also prevents group node sockets from being removed, without the need to explicitly
 
601
         * check the node type here.
 
602
         */
 
603
        if (ntype && ((ntype->inputs && ntype->inputs[0].type>=0) || (ntype->outputs && ntype->outputs[0].type>=0))) {
 
604
                verify_socket_template_list(ntree, node, SOCK_IN, &node->inputs, ntype->inputs);
 
605
                verify_socket_template_list(ntree, node, SOCK_OUT, &node->outputs, ntype->outputs);
 
606
        }
 
607
}