forked from ahmidou/SpliceSoftimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.cpp
More file actions
672 lines (599 loc) · 26.3 KB
/
Copy pathcommands.cpp
File metadata and controls
672 lines (599 loc) · 26.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
#include <xsi_application.h>
#include <xsi_context.h>
#include <xsi_status.h>
#include <xsi_command.h>
#include <xsi_argument.h>
#include <xsi_factory.h>
#include <xsi_longarray.h>
#include <xsi_doublearray.h>
#include <xsi_math.h>
#include <xsi_customproperty.h>
#include <xsi_ppglayout.h>
#include <xsi_menu.h>
#include <xsi_selection.h>
#include <xsi_project.h>
#include <xsi_scene.h>
#include <xsi_utils.h>
#include <xsi_customoperator.h>
#include <boost/filesystem.hpp>
// project includes
#include "plugin.h"
#include "dialogs.h"
#include "commands.h"
#include "FabricSpliceBaseInterface.h"
#include "renderpass.h"
using namespace XSI;
void xsiUpdateOp(unsigned int objectID)
{
CustomOperator op(Application().GetObjectFromID(objectID));
if(!op.IsValid())
return;
LONG evalID = op.GetParameterValue("evalID");
op.PutParameterValue("evalID", (evalID + 1) % 1000);
}
SICALLBACK fabricSplice_Init(CRef & in_ctxt)
{
Context ctxt( in_ctxt );
Command oCmd;
oCmd = ctxt.GetSource();
oCmd.PutDescription(L"Edits a Fabric:Splice Operator");
oCmd.SetFlag(siNoLogging,false);
oCmd.EnableReturnValue( true ) ;
ArgumentArray oArgs = oCmd.GetArguments();
oArgs.Add(L"action");
oArgs.Add(L"reference");
oArgs.Add(L"data");
oArgs.Add(L"auxiliary");
return CStatus::OK;
}
SICALLBACK fabricSplice_Execute(CRef & in_ctxt)
{
FabricSplice::Logging::AutoTimer("fabricSplice_Execute");
xsiClearError();
CStatus status = CStatus::OK;
xsiInitializeSplice();
Context ctxt( in_ctxt );
CValueArray args = ctxt.GetAttribute(L"Arguments");
try
{
CString actionStr = CString(args[0]);
CString referenceStr = CString(args[1]);
CString dataStr = CString(args[2]);
CString auxiliaryStr = CString(args[3]);
FabricCore::Variant scriptArgs;
if(actionStr == "constructClient")
{
bool clientCreated = FabricSplice::ConstructClient().isValid();
ctxt.PutAttribute(L"ReturnValue", clientCreated);
return xsiErrorOccured();
}
else if(actionStr == "destroyClient")
{
bool clientDestroyed = FabricSplice::DestroyClient();
ctxt.PutAttribute(L"ReturnValue", clientDestroyed);
return xsiErrorOccured();
}
else if(actionStr == "getClientContextID")
{
CString clientContextID = FabricSplice::GetClientContextID();
ctxt.PutAttribute(L"ReturnValue", clientContextID);
return xsiErrorOccured();
}
else if(actionStr == "registerKLType")
{
CString rtStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "rt").c_str();
CString extStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "extension", "", true).c_str();
if(!extStr.IsEmpty())
FabricSplice::DGGraph::loadExtension(extStr.GetAsciiString());
FabricSplice::DGGraph::loadExtension(rtStr.GetAsciiString());
return xsiErrorOccured();
}
else if(actionStr.IsEqualNoCase("startProfiling"))
{
FabricSplice::Logging::enableTimers();
for(unsigned int i=0;i<FabricSplice::Logging::getNbTimers();i++)
{
FabricSplice::Logging::resetTimer(FabricSplice::Logging::getTimerName(i));
}
return xsiErrorOccured();
}
else if(actionStr.IsEqualNoCase("stopProfiling"))
{
for(unsigned int i=0;i<FabricSplice::Logging::getNbTimers();i++)
{
FabricSplice::Logging::logTimer(FabricSplice::Logging::getTimerName(i));
}
FabricSplice::Logging::disableTimers();
return xsiErrorOccured();
}
if(actionStr.IsEqualNoCase(L"newsplice") || actionStr.IsEqualNoCase(L"loadsplice"))
{
scriptArgs = FabricSplice::Scripting::parseScriptingArguments(
actionStr.GetAsciiString(), "",
referenceStr.GetAsciiString(), dataStr.GetAsciiString());
}
else
{
scriptArgs = FabricSplice::Scripting::parseScriptingArguments(
actionStr.GetAsciiString(), referenceStr.GetAsciiString(),
dataStr.GetAsciiString(), auxiliaryStr.GetAsciiString());
}
// fetch the relevant arguments
actionStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "action").c_str();
// optional arguments
referenceStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "reference", "", true).c_str();
auxiliaryStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "auxiliary", "", true).c_str();
// get the operator from string or ID
CRef opRef;
opRef.Set(referenceStr);
// if we have a valid operator, let's try to get the base interface
FabricSpliceBaseInterface * interf = FabricSpliceBaseInterface::getInstanceByObjectID(ProjectItem(opRef).GetObjectID());
if(actionStr.IsEqualNoCase("newSplice"))
{
// parse args
CString targetsStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "targets").c_str();
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode", "DGNode", true).c_str();
FabricSplice::Port_Mode portMode = FabricSplice::Port_Mode_OUT;
CString portModeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portMode", "", true).c_str();
if(!portModeStr.IsEmpty())
{
if(portModeStr.IsEqualNoCase(L"io"))
portMode = FabricSplice::Port_Mode_IO;
}
CRefArray targetRefs = getCRefArrayFromCString(targetsStr);
if(targetRefs.GetCount() == 0)
{
xsiLogErrorFunc("'targets' script argument '"+targetsStr+"' is not valid.");
return CStatus::InvalidArgument;
}
CString targetDataType = getSpliceDataTypeFromRefArray(targetRefs);
if(targetDataType.IsEmpty())
{
xsiLogErrorFunc("'targets' script argument uses unsupported data type.");
return CStatus::InvalidArgument;
}
interf = new FabricSpliceBaseInterface();
if(!interf->addXSIPort(targetRefs, portNameStr, targetDataType, portMode, dgNodeStr).Succeeded())
return CStatus::Unexpected;
if(!interf->updateXSIOperator().Succeeded())
return CStatus::Unexpected;
CRef ofRef = Application().GetObjectFromID((LONG)interf->getObjectID());
ctxt.PutAttribute(L"ReturnValue", ofRef.GetAsText());
}
else if(actionStr.IsEqualNoCase("loadSplice"))
{
// parse args
CString fileNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "fileName").c_str();
bool hideUI = FabricSplice::Scripting::consumeBooleanArgument(scriptArgs, "hideUI", false, true);
interf = new FabricSpliceBaseInterface();
CStatus loadResult = interf->loadFromFile(fileNameStr, scriptArgs, hideUI);
if(!loadResult.Succeeded())
{
if(loadResult == CStatus::NotImpl)
{
delete(interf);
return CStatus::Unexpected;
}
else if(!hideUI)
{
ImportSpliceDialog dialog(fileNameStr);
interf->setObjectID(dialog.getProp().GetObjectID());
dialog.show(L"Define Splice Ports");
return xsiErrorOccured();
}
return CStatus::Unexpected;
}
CRef ofRef = Application().GetObjectFromID((LONG)interf->getObjectID());
ctxt.PutAttribute(L"ReturnValue", ofRef.GetAsText());
}
else if(actionStr.IsEqualNoCase("toggleRenderer"))
{
enableRTRPass(!isRTRPassEnabled());
}
else
{
if(interf == NULL)
{
xsiLogErrorFunc("No valid spliceOp specified (arg0).");
return CStatus::InvalidArgument;
}
if(actionStr.IsEqualNoCase("saveSplice"))
{
CString fileNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "fileName").c_str();
if(!interf->saveToFile(fileNameStr).Succeeded())
return CStatus::Unexpected;
}
else if(actionStr.IsEqualNoCase("addDGNode"))
{
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode").c_str();
interf->getSpliceGraph().constructDGNode(dgNodeStr.GetAsciiString());
return xsiErrorOccured();
}
else if(actionStr.IsEqualNoCase("removeDGNode"))
{
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode").c_str();
interf->getSpliceGraph().removeDGNode(dgNodeStr.GetAsciiString());
return xsiErrorOccured();
}
else if(actionStr.IsEqualNoCase("setDGNodeDependency"))
{
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode", "DGNode", true).c_str();
CString dependencyStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dependency").c_str();
interf->getSpliceGraph().setDGNodeDependency(dgNodeStr.GetAsciiString(), dependencyStr.GetAsciiString());
return xsiErrorOccured();
}
else if(actionStr.IsEqualNoCase("removeDGNodeDependency"))
{
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode", "DGNode", true).c_str();
CString dependencyStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dependency").c_str();
interf->getSpliceGraph().removeDGNodeDependency(dgNodeStr.GetAsciiString(), dependencyStr.GetAsciiString());
return xsiErrorOccured();
}
else if(actionStr.IsEqualNoCase("addParameter"))
{
// parse args
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
CString dataTypeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dataType").c_str();
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode", "DGNode", true).c_str();
CString portModeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portMode", "in", true).c_str();
CString extStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "extension", "", true).c_str();
FabricCore::Variant defaultValue;
if(auxiliaryStr.Length() > 0)
defaultValue = FabricCore::Variant::CreateFromJSON(auxiliaryStr.GetAsciiString());
if(!interf->addXSIParameter(processNameCString(portNameStr), dataTypeStr, portModeStr, processNameCString(dgNodeStr), defaultValue, extStr).Succeeded())
return CStatus::Unexpected;
// add all additional arguments as flags on the port
FabricSplice::DGPort port = interf->getSpliceGraph().getDGPort(portNameStr.GetAsciiString());
if(port.isValid())
{
for(FabricCore::Variant::DictIter keyIter(scriptArgs); !keyIter.isDone(); keyIter.next())
{
std::string key = keyIter.getKey()->getStringData();
FabricCore::Variant value = *keyIter.getValue();
if(value.isNull())
continue;
port.setOption(key.c_str(), value);
}
}
if(!interf->updateXSIOperator().Succeeded())
return CStatus::Unexpected;
}
else if(actionStr.IsEqualNoCase("addInputPort") || actionStr.IsEqualNoCase("addOutputPort") || actionStr.IsEqualNoCase("addIOPort"))
{
// parse args
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
CString iceAttrStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "iceAttribute", "", true).c_str();
CString dataTypeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dataType", "", !iceAttrStr.IsEmpty()).c_str();
CString targetsStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "targets").c_str();
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode", "DGNode", true).c_str();
CRefArray targetRefs = getCRefArrayFromCString(targetsStr);
if(targetRefs.GetCount() == 0)
{
xsiLogErrorFunc("data json targets '"+targetsStr+"' is not valid.");
return CStatus::InvalidArgument;
}
FabricSplice::Port_Mode portMode = FabricSplice::Port_Mode_IN;
if(actionStr.IsEqualNoCase("addOutputPort"))
portMode = FabricSplice::Port_Mode_OUT;
else if(actionStr.IsEqualNoCase("addIOPort"))
portMode = FabricSplice::Port_Mode_IO;
CString targetDataType;
if(iceAttrStr.IsEmpty())
{
targetDataType = getSpliceDataTypeFromRefArray(targetRefs, dataTypeStr);
if(targetDataType.IsEmpty())
{
xsiLogErrorFunc("Target(s) used for port uses an unsupported data type. Please match the target(s) used with the dataType '"+dataTypeStr+"'.");
return CStatus::InvalidArgument;
}
}
else
{
CString errorMessageStr;
targetDataType = getSpliceDataTypeFromICEAttribute(targetRefs, iceAttrStr, errorMessageStr);
if(targetDataType.IsEmpty())
{
xsiLogErrorFunc(errorMessageStr);
return CStatus::InvalidArgument;
}
}
if(!dataTypeStr.IsEmpty())
{
if(dataTypeStr != targetDataType && dataTypeStr != targetDataType + "[]")
{
xsiLogErrorFunc("Data types do not match ('" + dataTypeStr + "', '" + targetDataType + "').");
return CStatus::Unexpected;
}
targetDataType = dataTypeStr;
}
if(iceAttrStr.IsEmpty())
{
if(!interf->addXSIPort(targetRefs, processNameCString(portNameStr), targetDataType, portMode, processNameCString(dgNodeStr)).Succeeded())
return CStatus::Unexpected;
}
else
{
if(!interf->addXSIICEPort(targetRefs, processNameCString(portNameStr), targetDataType, iceAttrStr, processNameCString(dgNodeStr)).Succeeded())
return CStatus::Unexpected;
}
// add all additional arguments as flags on the port
FabricSplice::DGPort port = interf->getSpliceGraph().getDGPort(portNameStr.GetAsciiString());
if(port.isValid())
{
for(FabricCore::Variant::DictIter keyIter(scriptArgs); !keyIter.isDone(); keyIter.next())
{
std::string key = keyIter.getKey()->getStringData();
FabricCore::Variant value = *keyIter.getValue();
if(value.isNull())
continue;
port.setOption(key.c_str(), value);
}
}
if(!interf->updateXSIOperator().Succeeded())
return CStatus::Unexpected;
}
else if(actionStr.IsEqualNoCase("addInternalPort"))
{
// parse args
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
CString dataTypeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dataType").c_str();
CString portModeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portMode", "io", true).c_str();
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode", "DGNode", true).c_str();
CString extStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "extension", "", true).c_str();
bool autoInitObjects = FabricSplice::Scripting::consumeBooleanArgument(scriptArgs, "autoInitObjects", true, true);
FabricSplice::Port_Mode portMode = FabricSplice::Port_Mode_IO;
if(portModeStr.IsEqualNoCase(L"in"))
portMode = FabricSplice::Port_Mode_IN;
if(portModeStr.IsEqualNoCase(L"out"))
portMode = FabricSplice::Port_Mode_OUT;
FabricCore::Variant defaultValue;
if(auxiliaryStr.Length() > 0)
defaultValue = FabricCore::Variant::CreateFromJSON(auxiliaryStr.GetAsciiString());
if(!interf->addSplicePort(processNameCString(portNameStr), dataTypeStr, portMode, processNameCString(dgNodeStr), autoInitObjects, defaultValue, extStr).Succeeded())
return CStatus::Unexpected;
// add all additional arguments as flags on the port
FabricSplice::DGPort port = interf->getSpliceGraph().getDGPort(portNameStr.GetAsciiString());
if(port.isValid())
{
for(FabricCore::Variant::DictIter keyIter(scriptArgs); !keyIter.isDone(); keyIter.next())
{
std::string key = keyIter.getKey()->getStringData();
FabricCore::Variant value = *keyIter.getValue();
if(value.isNull())
continue;
port.setOption(key.c_str(), value);
}
}
xsiUpdateOp(interf->getObjectID());
}
else if(actionStr.IsEqualNoCase("removePort"))
{
// parse args
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
if(!interf->removeSplicePort(portNameStr).Succeeded())
return CStatus::Unexpected;
if(!interf->updateXSIOperator().Succeeded())
return CStatus::Unexpected;
}
else if(actionStr.IsEqualNoCase("reroutePort"))
{
// parse args
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
if(!interf->rerouteXSIPort(portNameStr, scriptArgs).Succeeded())
return CStatus::Unexpected;
if(!interf->updateXSIOperator().Succeeded())
return CStatus::Unexpected;
}
else if(actionStr.IsEqualNoCase("addKLOperator"))
{
// parse args
CString opNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "opName").c_str();
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode", "DGNode", true).c_str();
CString entryStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "entry", "", true).c_str();
CString klCode = auxiliaryStr;
FabricCore::Variant portMap = FabricSplice::Scripting::consumeVariantArgument(scriptArgs, "portMap", FabricCore::Variant::CreateDict(), true);
opNameStr = processNameCString(opNameStr);
if(klCode.IsEmpty())
klCode = interf->getSpliceGraph().generateKLOperatorSourceCode(opNameStr.GetAsciiString()).getStringData();
if(!interf->addKLOperator(opNameStr, klCode, processNameCString(entryStr), processNameCString(dgNodeStr), portMap).Succeeded())
return CStatus::Unexpected;
xsiUpdateOp(interf->getObjectID());
}
else if(actionStr.IsEqualNoCase("setKLOperatorCode"))
{
// parse args
CString opNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "opName").c_str();
CString klCode = auxiliaryStr;
CString entryStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "entry", "", true).c_str();
if(klCode.IsEmpty())
{
xsiLogErrorFunc("No kl specified.");
return CStatus::InvalidArgument;
}
if(!interf->setKLOperatorCode(processNameCString(opNameStr), klCode, processNameCString(entryStr)).Succeeded())
return CStatus::Unexpected;
xsiUpdateOp(interf->getObjectID());
}
else if(actionStr.IsEqualNoCase("getKLOperatorCode"))
{
// parse args
CString opNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "opName").c_str();
CString code = interf->getKLOperatorCode(processNameCString(opNameStr));
ctxt.PutAttribute(L"ReturnValue", code);
}
else if(actionStr.IsEqualNoCase("setKLOperatorFile"))
{
// parse args
CString opNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "opName").c_str();
CString fileNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "fileName").c_str();
CString entryStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "entry", "", true).c_str();
if(!interf->setKLOperatorFile(processNameCString(opNameStr), fileNameStr, entryStr).Succeeded())
return CStatus::Unexpected;
xsiUpdateOp(interf->getObjectID());
}
else if(actionStr.IsEqualNoCase("setKLOperatorEntry"))
{
// parse args
CString opNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "opName").c_str();
CString entryStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "entry").c_str();
if(!interf->setKLOperatorEntry(processNameCString(opNameStr), entryStr).Succeeded())
return CStatus::Unexpected;
xsiUpdateOp(interf->getObjectID());
}
else if(actionStr.IsEqualNoCase("setKLOperatorIndex"))
{
// parse args
CString opNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "opName").c_str();
int opIndex = FabricSplice::Scripting::consumeIntegerArgument(scriptArgs, "index");
if(!interf->setKLOperatorIndex(processNameCString(opNameStr), opIndex).Succeeded())
return CStatus::Unexpected;
xsiUpdateOp(interf->getObjectID());
}
else if(actionStr.IsEqualNoCase("removeKLOperator"))
{
// parse args
CString opNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "opName").c_str();
CString dgNodeStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "dgNode", "DGNode", true).c_str();
if(!interf->removeKLOperator(opNameStr, dgNodeStr).Succeeded())
return CStatus::Unexpected;
xsiUpdateOp(interf->getObjectID());
}
else if(actionStr.IsEqualNoCase("getPortInfo"))
{
ctxt.PutAttribute(L"ReturnValue", interf->getDGPortInfo());
}
else if(actionStr.IsEqualNoCase("setPortPersistence"))
{
// parse args
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
bool persistence = FabricSplice::Scripting::consumeBooleanArgument(scriptArgs, "persistence");
interf->getSpliceGraph().setMemberPersistence(processNameCString(portNameStr).GetAsciiString(), persistence);
}
else if(actionStr.IsEqualNoCase("getPortData"))
{
// parse args
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
FabricSplice::DGPort port = interf->getSpliceGraph().getDGPort(processNameCString(portNameStr).GetAsciiString());
if(!port.isValid())
{
xsiLogErrorFunc("port '"+portNameStr+"' does not exist.");
return CStatus::InvalidArgument;
}
if(port.getSliceCount() != 1)
{
xsiLogErrorFunc("port '"+portNameStr+"' has multiple slices.");
return CStatus::InvalidArgument;
}
FabricCore::Variant portDataVar = port.getVariant();
CString portData = portDataVar.getJSONEncoding().getStringData();
ctxt.PutAttribute(L"ReturnValue", portData);
}
else if(actionStr.IsEqualNoCase("setPortData"))
{
// parse args
CString portNameStr = FabricSplice::Scripting::consumeStringArgument(scriptArgs, "portName").c_str();
FabricSplice::DGPort port = interf->getSpliceGraph().getDGPort(processNameCString(portNameStr).GetAsciiString());
if(!port.isValid())
{
xsiLogErrorFunc("port '"+portNameStr+"' does not exist.");
return CStatus::InvalidArgument;
}
if(port.getSliceCount() != 1)
{
xsiLogErrorFunc("port '"+portNameStr+"' has multiple slices.");
return CStatus::InvalidArgument;
}
if(port.getMode() == FabricSplice::Port_Mode_OUT)
{
xsiLogErrorFunc("port '"+portNameStr+"' is an output port.");
return CStatus::InvalidArgument;
}
CString portData = auxiliaryStr;
FabricCore::Variant portDataVar = FabricCore::Variant::CreateFromJSON(portData.GetAsciiString());
port.setVariant(portDataVar);
interf->getSpliceGraph().setMemberPersistence(processNameCString(portNameStr).GetAsciiString(), true);
}
else
{
xsiLogErrorFunc("action argument uses invalid value '"+actionStr+"'");
return CStatus::InvalidArgument;
}
}
}
catch(FabricSplice::Exception e)
{
return CStatus::Unexpected;
}
return xsiErrorOccured();
}
SICALLBACK proceedToNextScene_Init(CRef & in_ctxt)
{
Context ctxt( in_ctxt );
Command oCmd;
oCmd = ctxt.GetSource();
oCmd.PutDescription(L"Loads the next scene in sequence.");
oCmd.SetFlag(siNoLogging,false);
oCmd.EnableReturnValue( true ) ;
ArgumentArray oArgs = oCmd.GetArguments();
return CStatus::OK;
}
SICALLBACK proceedToNextScene_Execute(CRef & in_ctxt)
{
CStatus status = CStatus::OK;
CString sceneFileName = xsiGetLastLoadedScene();
boost::filesystem::path currentSample = sceneFileName.GetAsciiString();
boost::filesystem::path samplesDir = currentSample.parent_path();
while(samplesDir.stem().string() != "Samples" && samplesDir.stem().string() != "Splice") {
samplesDir = samplesDir.parent_path();
if(samplesDir.empty()) {
Application().LogMessage("You can only use proceedToNextScene on the Fabric Engine sample scenes.", siWarningMsg);
return status;
}
}
std::vector<boost::filesystem::path> sampleScenes;
std::vector<boost::filesystem::path> folders;
folders.push_back(samplesDir);
for(size_t i=0;i<folders.size();i++)
{
if(!boost::filesystem::exists(folders[i]))
continue;
if(!boost::filesystem::is_directory(folders[i]))
continue;
boost::filesystem::directory_iterator end_iter;
for( boost::filesystem::directory_iterator dir_iter(folders[i]) ; dir_iter != end_iter ; ++dir_iter)
{
if(boost::filesystem::is_directory(dir_iter->path()))
{
folders.push_back(dir_iter->path());
}
else if(dir_iter->path().extension().string() == ".scn" ||
dir_iter->path().extension().string() == ".Scn" ||
dir_iter->path().extension().string() == ".SCN")
{
sampleScenes.push_back(dir_iter->path());
}
}
}
boost::filesystem::path nextSample;
for(size_t i=0;i<sampleScenes.size();i++) {
if(sampleScenes[i] == currentSample)
{
if(i < sampleScenes.size() - 1)
nextSample = sampleScenes[i+1];
else
nextSample = sampleScenes[0];
break;
}
}
if(!nextSample.empty()) {
Application().LogMessage("Opening next scene: "+CString(nextSample.string().c_str()));
CValueArray args(3);
args[0] = CString(nextSample.string().c_str());
args[1] = false;
args[2] = false;
CValue returnVal;
Application().ExecuteCommand("OpenScene", args, returnVal);
}
return status;
}