-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMeshGitCmd.cpp
More file actions
257 lines (206 loc) · 6.69 KB
/
Copy pathMeshGitCmd.cpp
File metadata and controls
257 lines (206 loc) · 6.69 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
#include "MeshGitFn.h"
#include "MeshGitLocatorNode.h"
#include "MeshGitCmd.h"
#include <maya/MGlobal.h>
#include <maya/MSyntax.h>
#include <maya/MArgDatabase.h>
#include <maya/MPlugArray.h>
#include <maya/MSelectionList.h>
#include <maya/MDGModifier.h>
#include <maya/MDagModifier.h>
#include <list>
using namespace std;
#include <sstream>
//Command line flags
const char *originalFlag = "-o", *originalLongFlag = "-original";
const char *aFlag = "-a", *aLongFlag = "-derivativeA";
const char *bFlag = "-b", *bLongFlag = "-derivativeB";
const char *connectFlag = "-c", *connectLongFlag= "-connectNodes";
const char *diffFlag = "-d", *diffLongFlag= "-startDiff";
const char *mergeUnconflictingFlag = "-mu", *mergeUnconflictingLongFlag = "-mergeUnconflicting";
const char *updateSelectedEditFlag = "-us", *updateSelectedEditLongFlag = "-updateSelectedEdit";
const char *resolveConflictFlag = "rc", *resolveConflictLongFlag = "-resolveConflict";
MeshGitCmd::MeshGitCmd() : MPxCommand()
{
}
MeshGitCmd::~MeshGitCmd()
{
}
MStatus MeshGitCmd::doIt( const MArgList& args )
{
MStatus status;
MArgDatabase argData( syntax(), args, &status );
if (!status)
return status;
MString originalFilepath = "";
MString aFilepath = "";
MString bFilepath = "";
MString meshGitNodeName;
MString locatorNodeName;
MString resolveConflict ="";
//Set flags
if (argData.isFlagSet(originalFlag)) { argData.getFlagArgument(originalFlag, 0, originalFilepath); }
if (argData.isFlagSet(aFlag)) { argData.getFlagArgument(aFlag, 0, aFilepath); }
if (argData.isFlagSet(bFlag)) { argData.getFlagArgument(bFlag, 0, bFilepath); }
if (argData.isFlagSet(connectFlag)) {
argData.getFlagArgument(connectFlag, 0, meshGitNodeName);
argData.getFlagArgument(connectFlag, 1, locatorNodeName);
connectNodes(meshGitNodeName, locatorNodeName);
}
if (argData.isFlagSet(diffFlag)) {
argData.getFlagArgument(diffFlag, 0, meshGitNodeName);
startDiff(meshGitNodeName);
}
if (argData.isFlagSet(mergeUnconflictingFlag)) {
argData.getFlagArgument(mergeUnconflictingFlag, 0, meshGitNodeName);
startMergeUnconflicting(meshGitNodeName);
}
if (argData.isFlagSet(updateSelectedEditFlag)) {
argData.getFlagArgument(updateSelectedEditFlag, 0, meshGitNodeName);
startUpdateSelectedEdit(meshGitNodeName);
}
if (argData.isFlagSet(resolveConflictFlag)) {
argData.getFlagArgument(resolveConflictFlag, 0, resolveConflict);
argData.getFlagArgument(resolveConflictFlag, 1, meshGitNodeName);
manualResolveConflict(resolveConflict, meshGitNodeName);
}
MGlobal::displayInfo(originalFilepath);
return MStatus::kSuccess;
}
MSyntax MeshGitCmd::newSyntax()
{
MSyntax syntax;
syntax.addFlag(originalFlag, originalLongFlag, MSyntax::kString);
syntax.addFlag(aFlag, aLongFlag, MSyntax::kString);
syntax.addFlag(bFlag, bLongFlag, MSyntax::kString);
syntax.addFlag(connectFlag, connectLongFlag, MSyntax::kString, MSyntax::kString);
syntax.addFlag(diffFlag, diffLongFlag, MSyntax::kString);
syntax.addFlag(mergeUnconflictingFlag, mergeUnconflictingLongFlag, MSyntax::kString);
syntax.addFlag(updateSelectedEditFlag, updateSelectedEditLongFlag, MSyntax::kString);
syntax.addFlag(resolveConflictFlag, resolveConflictLongFlag, MSyntax::kString, MSyntax::kString);
return syntax;
}
std::string stringify(double x)
{
std::stringstream s;
s << "(" << x << ")";
return s.str();
}
void MeshGitCmd::startDiff(MString nodeName){
MGlobal::displayInfo("Starting diff on Node: " + nodeName );
MStatus status;
//Get Node Object
MSelectionList nodeList;
status = nodeList.add(nodeName);
MObject nodeObject;
status = nodeList.getDependNode(0, nodeObject);
reportError(status);
//Create Node Fn
MeshGitFn mgFn;
status = mgFn.setObject(nodeObject);
reportError(status);
//Start the diff
mgFn.startDiff();
//mgFn.get
//Get the node plug
MPlug nodePlug = mgFn.findPlug("message", true, &status);
reportError(status);
}
void MeshGitCmd::startMergeUnconflicting(MString nodeName){
MGlobal::displayInfo("Starting diff on Node: " + nodeName );
MStatus status;
//Get Node Object
MSelectionList nodeList;
status = nodeList.add(nodeName);
MObject nodeObject;
status = nodeList.getDependNode(0, nodeObject);
reportError(status);
//Create Node Fn
MeshGitFn mgFn;
status = mgFn.setObject(nodeObject);
reportError(status);
//Start the diff
mgFn.startMergeUnconflicting();
//mgFn.get
//Get the node plug
//MPlug nodePlug = mgFn.findPlug("message", true, &status);
reportError(status);
}
void MeshGitCmd::connectNodes(MString nodeName, MString locatorName){
MGlobal::displayInfo("Connecting " + nodeName + " and " + locatorName);
MStatus status;
//Get Node Object
MSelectionList nodeList;
status = nodeList.add(nodeName);
MObject nodeObject;
status = nodeList.getDependNode(0, nodeObject);
reportError(status);
//Get Viz Object
MSelectionList vizList;
status = vizList.add(locatorName);
MObject vizObject;
status = vizList.getDependNode(0, vizObject);
reportError(status);
//Create Node Fn
MeshGitFn mgFn;
status = mgFn.setObject(nodeObject);
reportError(status);
//Create viz fn
MFnDependencyNode vizFn(vizObject, &status);
//Get the node plug
MPlug nodePlug = mgFn.findPlug("message", true, &status);
reportError(status);
//Get the viz plug
MPlug vizPlug = vizFn.findPlug(MeshGitLocatorNode::meshGitNodeConnection, true,
&status);
//Connect the plugs
MDagModifier modifier;
status = modifier.connect(nodePlug,vizPlug);
reportError(status);
status = modifier.doIt();
}
void MeshGitCmd::reportError(MStatus status ){
if(status != MStatus::kSuccess){
MGlobal::displayInfo("ERROR " + status.errorString());
}
}
void MeshGitCmd::startUpdateSelectedEdit(MString nodeName){
cout<< "Starting updating selected edit on Node: " + nodeName << endl;
MStatus status;
if(nodeName == NULL || nodeName ==""){
cout<< "nodeName == NULL " + nodeName << endl;
return;
}
//Get Node Object
MSelectionList nodeList;
status = nodeList.add(nodeName);
MObject nodeObject;
status = nodeList.getDependNode(0, nodeObject);
reportError(status);
//Create Node Fn
MeshGitFn mgFn;
status = mgFn.setObject(nodeObject);
reportError(status);
//Start the diff
mgFn.findSelectedEditIndex();
reportError(status);
}
void MeshGitCmd::manualResolveConflict(MString resolution, MString nodeName)
{
MStatus status;
if(nodeName == NULL || nodeName =="") return;
//Get Node Object
MSelectionList nodeList;
status = nodeList.add(nodeName);
MObject nodeObject;
status = nodeList.getDependNode(0, nodeObject);
reportError(status);
//Create Node Fn
MeshGitFn mgFn;
status = mgFn.setObject(nodeObject);
reportError(status);
//Resolve conflict with resolution
int rc = resolution.asInt();
mgFn.manualResolveConflict(rc);
reportError(status);
}