-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathplugin.cpp
More file actions
316 lines (272 loc) · 11.4 KB
/
Copy pathplugin.cpp
File metadata and controls
316 lines (272 loc) · 11.4 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
#include <xsi_application.h>
#include <xsi_customoperator.h>
#include <xsi_projectitem.h>
#include <xsi_pluginregistrar.h>
#include <xsi_uitoolkit.h>
#include <xsi_plugin.h>
#include "plugin.h"
#include "FabricDFGBaseInterface.h"
#include "FabricDFGPlugin.h"
#include "FabricDFGOperators.h"
#include "FabricDFGTools.h"
#include "FabricSplicePlugin.h"
#include "FabricSpliceICENodes.h"
#include <FabricUI/DFG/DFGUICmd/DFGUICmds.h>
#include <QtGui/QApplication>
using namespace XSI;
// for registering the DFGUICmdHandler custom commands.
#define REGISTER_DFGUICMD(inreg, CMD) \
{ \
std::wstring cmdName( \
FabricUI::DFG::DFGUICmd_##CMD::CmdName().begin(), \
FabricUI::DFG::DFGUICmd_##CMD::CmdName().end() \
); \
in_reg.RegisterCommand( cmdName.c_str(), cmdName.c_str() ); \
ccnames.Add( cmdName.c_str() ); \
}
// load plugin.
SICALLBACK XSILoadPlugin(PluginRegistrar& in_reg)
{
// check if the Fabric environment variables are set.
const int numEnvVars = 3;
std::string envVarNames [numEnvVars];
std::string envVarExamples[numEnvVars];
envVarNames [0] = "FABRIC_DIR";
envVarNames [1] = "FABRIC_DFG_PATH";
envVarNames [2] = "FABRIC_EXTS_PATH";
#ifdef _WIN32
envVarExamples[0] = "<Fabric-Installation-Path>";
envVarExamples[1] = "<Fabric-Installation-Path>\\Presets\\DFG";
envVarExamples[2] = "<Fabric-Installation-Path>\\Exts";
#else
envVarExamples[0] = "<Fabric-Installation-Path>";
envVarExamples[1] = "<Fabric-Installation-Path>/Presets/DFG";
envVarExamples[2] = "<Fabric-Installation-Path>/Exts";
#endif
for (int i=0;i<numEnvVars;i++)
{
// get the environment variable's value.
char *envVarValue = getenv(envVarNames[i].c_str());
// no value found?
if (!envVarValue || envVarValue[0] == '\0')
{
// log error.
std::string t = "The environment variable " + envVarNames[i] + " is not set. Please make sure that " + envVarNames[i] + " is set and points to \"" + envVarExamples[i] + "\".";
Application().LogMessage(L"[Fabric]: " + CString(t.c_str()), siErrorMsg);
}
}
// set plugin's name, version and author.
in_reg.PutAuthor(L"Fabric Engine");
in_reg.PutName (L"Fabric Engine Plugin");
in_reg.PutVersion(FabricCore::GetVersionMaj(), FabricCore::GetVersionMin());
// register the legacy Fabric Splice.
{
// rendering.
in_reg.RegisterDisplayCallback(L"SpliceRenderPass");
// properties.
in_reg.RegisterProperty(L"SpliceInfo");
// dialogs.
in_reg.RegisterProperty(L"SpliceEditor");
in_reg.RegisterProperty(L"ImportSpliceDialog");
// operators.
in_reg.RegisterOperator(L"SpliceOp");
// commands.
in_reg.RegisterCommand(L"fabricSplice", L"fabricSplice");
in_reg.RegisterCommand(L"fabricSpliceManipulation", L"fabricSpliceManipulation");
in_reg.RegisterCommand(L"proceedToNextScene", L"proceedToNextScene");
// tools.
in_reg.RegisterTool(L"fabricSpliceTool");
// events.
in_reg.RegisterEvent(L"FabricSpliceNewScene", siOnEndNewScene);
in_reg.RegisterEvent(L"FabricSpliceCloseScene", siOnCloseScene);
in_reg.RegisterEvent(L"FabricSpliceOpenBeginScene", siOnBeginSceneOpen);
in_reg.RegisterEvent(L"FabricSpliceOpenEndScene", siOnEndSceneOpen);
in_reg.RegisterEvent(L"FabricSpliceSaveScene", siOnBeginSceneSave);
in_reg.RegisterEvent(L"FabricSpliceSaveAsScene", siOnBeginSceneSaveAs);
in_reg.RegisterEvent(L"FabricSpliceTerminate", siOnTerminate);
in_reg.RegisterEvent(L"FabricSpliceSaveScene2", siOnBeginSceneSave2);
in_reg.RegisterEvent(L"FabricSpliceImport", siOnEndFileImport);
in_reg.RegisterEvent(L"FabricSpliceBeginExport", siOnBeginFileExport);
in_reg.RegisterEvent(L"FabricSpliceEndExport", siOnEndFileExport);
in_reg.RegisterEvent(L"FabricSpliceValueChange", siOnValueChange);
// ice nodes.
Register_spliceGetData(in_reg);
}
// array of custom command names.
CStringArray ccnames;
// register the new Fabric Canvas.
{
// operators.
in_reg.RegisterOperator(L"CanvasOp");
// commands.
CString cmdName;
cmdName = L"FabricCanvasOpApply"; in_reg.RegisterCommand(cmdName, cmdName); ccnames.Add(cmdName);
cmdName = L"FabricCanvasOpPortMapDefine"; in_reg.RegisterCommand(cmdName, cmdName); ccnames.Add(cmdName);
cmdName = L"FabricCanvasOpConnectPort"; in_reg.RegisterCommand(cmdName, cmdName); ccnames.Add(cmdName);
cmdName = L"FabricCanvasOpPortMapQuery"; in_reg.RegisterCommand(cmdName, cmdName); ccnames.Add(cmdName);
cmdName = L"FabricCanvasImportGraph"; in_reg.RegisterCommand(cmdName, cmdName); ccnames.Add(cmdName);
cmdName = L"FabricCanvasExportGraph"; in_reg.RegisterCommand(cmdName, cmdName); ccnames.Add(cmdName);
cmdName = L"FabricCanvasSelectConnected"; in_reg.RegisterCommand(cmdName, cmdName); ccnames.Add(cmdName);
cmdName = L"FabricCanvasLogStatus"; in_reg.RegisterCommand(cmdName, cmdName); ccnames.Add(cmdName);
// commands for DFGUICmdHandler.
REGISTER_DFGUICMD( in_reg, AddBackDrop );
REGISTER_DFGUICMD( in_reg, AddFunc );
REGISTER_DFGUICMD( in_reg, AddGet );
REGISTER_DFGUICMD( in_reg, AddGraph );
REGISTER_DFGUICMD( in_reg, AddPort );
REGISTER_DFGUICMD( in_reg, AddSet );
REGISTER_DFGUICMD( in_reg, AddVar );
REGISTER_DFGUICMD( in_reg, Connect );
REGISTER_DFGUICMD( in_reg, Disconnect );
REGISTER_DFGUICMD( in_reg, EditPort );
REGISTER_DFGUICMD( in_reg, ExplodeNode );
REGISTER_DFGUICMD( in_reg, ImplodeNodes );
REGISTER_DFGUICMD( in_reg, InstPreset );
REGISTER_DFGUICMD( in_reg, MoveNodes );
REGISTER_DFGUICMD( in_reg, Paste );
REGISTER_DFGUICMD( in_reg, RenamePort );
REGISTER_DFGUICMD( in_reg, RemoveNodes );
REGISTER_DFGUICMD( in_reg, RemovePort );
REGISTER_DFGUICMD( in_reg, ResizeBackDrop );
REGISTER_DFGUICMD( in_reg, SetArgType );
REGISTER_DFGUICMD( in_reg, SetArgValue );
REGISTER_DFGUICMD( in_reg, SetExtDeps );
REGISTER_DFGUICMD( in_reg, SetCode );
REGISTER_DFGUICMD( in_reg, SetNodeComment );
REGISTER_DFGUICMD( in_reg, SetNodeTitle );
REGISTER_DFGUICMD( in_reg, SetPortDefaultValue );
REGISTER_DFGUICMD( in_reg, SetRefVarPath );
REGISTER_DFGUICMD( in_reg, SplitFromPreset );
REGISTER_DFGUICMD( in_reg, ReorderPorts );
// menu.
in_reg.RegisterMenu(siMenuMainTopLevelID, L"Fabric", true, true);
// events.
in_reg.RegisterEvent(L"FabricCanvasOnStartup", siOnStartup);
in_reg.RegisterEvent(L"FabricCanvasOnEndCommand", siOnEndCommand);
}
// sort the list of custom command names and log the result.
for (LONG i=ccnames.GetCount();i>1;i--) // simple bubble sort.
for (LONG j=0;j<i-1;j++)
if (ccnames[j] > ccnames[j + 1])
{
CString mem = ccnames[j];
ccnames[j] = ccnames[j + 1];
ccnames[j + 1] = mem;
}
for (LONG i=0;i<ccnames.GetCount();i++)
Application().LogMessage(L" " + ccnames[i]);
// done.
return CStatus::OK;
}
// unload plugin.
SICALLBACK XSIUnloadPlugin(const PluginRegistrar& in_reg)
{
CString strPluginName;
strPluginName = in_reg.GetName();
Application().LogMessage(strPluginName + L" has been unloaded.", siVerboseMsg);
// Qt.
if (qApp)
delete qApp;
// done.
return CStatus::OK;
}
// __________________________________
// siEvent + event helper functions.
// ----------------------------------
CStatus helpFnct_siEventOpenSave(CRef &ctxt, int openSave)
{
Context context(ctxt);
/*
openSave == 0: store DFG JSON in op's persistenceData parameter (e.g. before saving a scene).
openSave == 1: set DFG JSON from op's persistenceData parameter (e.g. after loading a scene).
*/
std::map <unsigned int, _opUserData *> &s_instances = *_opUserData::GetStaticMapOfInstances();
for (std::map<unsigned int, _opUserData *>::iterator it = s_instances.begin(); it != s_instances.end(); it++)
{
// get pointer at _opUserData.
_opUserData *pud = it->second;
if (!pud) continue;
// get the object ID of the CanvasOp operator to which the user data belongs to.
unsigned int opObjID = it->first;
// check if the user data has a base interface.
if (!pud->GetBaseInterface())
{ Application().LogMessage(L"user data has no base interface", siWarningMsg);
continue; }
// get the operator from the object ID.
ProjectItem pItem = Application().GetObjectFromID(opObjID);
if (!pItem.IsValid())
{ Application().LogMessage(L"Application().GetObjectFromID(opObjID) failed", siWarningMsg);
continue; }
CustomOperator op(pItem.GetRef());
if (!op.IsValid())
{ Application().LogMessage(L"CustomOperator op(pItem.GetRef()) failed", siWarningMsg);
continue; }
if (op.GetType() != L"CanvasOp")
{ Application().LogMessage(L"op.GetType() returned \"" + op.GetType() + L"\" instead of \"CanvasOp\"", siWarningMsg);
continue; }
// store JSON in parameter persistenceData.
if (openSave == 0)
{
Application().LogMessage(L"storing DFG JSON for CanvasOp(opObjID = " + CString(op.GetObjectID()) + L")");
try
{
CString dfgJSON = pud->GetBaseInterface()->getJSON().c_str();
if (op.PutParameterValue(L"persistenceData", dfgJSON) != CStatus::OK)
{ Application().LogMessage(L"op.PutParameterValue(L\"persistenceData\") failed!", siWarningMsg);
continue; }
}
catch (FabricCore::Exception e)
{
std::string s = std::string("failed: ") + (e.getDesc_cstr() ? e.getDesc_cstr() : "\"\"");
feLogError(s);
}
}
// set DFG JSON from parameter persistenceData.
else if (openSave == 1)
{
Application().LogMessage(L"setting DFG JSON from CanvasOp(opObjID = " + CString(op.GetObjectID()) + L")");
try
{
CString dfgJSON = op.GetParameterValue(L"persistenceData");
if (dfgJSON.IsEmpty())
{ Application().LogMessage(L"op.GetParameterValue(L\"persistenceData\") returned an empty value.", siWarningMsg);
continue; }
pud->GetBaseInterface()->setFromJSON(dfgJSON.GetAsciiString());
}
catch (FabricCore::Exception e)
{
std::string s = std::string("failed: ") + (e.getDesc_cstr() ? e.getDesc_cstr() : "\"\"");
feLogError(s);
}
dfgTools::ClearUndoHistory();
}
// do nothing.
else
{
continue;
}
}
// done.
// /note: we return 1 (i.e. "true") instead of CStatus::OK or else the event gets aborted).
return 1;
}
XSIPLUGINCALLBACK CStatus FabricCanvasOnStartup_OnEvent(CRef &ctxt)
{
// done.
// /note: we return 1 (i.e. "true") instead of CStatus::OK or else the event gets aborted).
return 1;
}
bool g_clearSoftimageUndoHistory = false;
XSIPLUGINCALLBACK CStatus FabricCanvasOnEndCommand_OnEvent(CRef &ctxt)
{
// if the global flag g_clearSoftimageUndoHistory is set then we clear Softimage's undo history and reset the flag.
if (g_clearSoftimageUndoHistory)
{
if (!dfgTools::ClearUndoHistory())
Application().LogMessage(L"failed to clear undo history", siWarningMsg);
g_clearSoftimageUndoHistory = false;
}
// done.
// /note: we return 1 (i.e. "true") instead of CStatus::OK or else the event gets aborted).
return 1;
}