forked from jhergel/icesl-nodes
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGraphMaker.cpp
More file actions
238 lines (208 loc) · 6.3 KB
/
Copy pathGraphMaker.cpp
File metadata and controls
238 lines (208 loc) · 6.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
#include "graphMaker.h"
#include <stack>
#include "NodeLua.h"
#include "hashlibpp.h"
#include "Resources.h"
using namespace std;
//------------------------------------------------------------------
void GraphMaker::onChange()
{
//create master script for emitNode
ofstream file;
file.open(masterScriptPath());
file << loadFileIntoString((Resources::path() + "/lua_constant/header.lua").c_str());
ForIndex(i, m_NodeGraph.nodeWindows.size()){
Node* n = m_NodeGraph.nodeWindows[i]->getNode();
if (n->isEmitingNode()){
n->writeMaster(file);
}
}
file.close();
Messaging::msg_update up;
up.val = 0;
Messaging::getInstance().send_update(up);
}
//------------------------------------------------------------------
void GraphMaker::deleteNodeWindow(NodeWindow* nw)
{
//remove all the connectiion
Node* toDelete = nw->getNode();
ForIndex(i, m_NodeGraph.nodeWindows.size()){
Node* n = m_NodeGraph.nodeWindows[i]->getNode();
//test if n is connected to the node to delete
n->removeConnectionTo(toDelete);
m_NodeGraph.nodeWindows[i]->removeConnectionTo(nw);
}
ForIndex(i, m_NodeGraph.nodeWindows.size()){
if (m_NodeGraph.nodeWindows[i] == nw){
m_NodeGraph.nodeWindows.erase(m_NodeGraph.nodeWindows.begin() + i);
break;
}
}
delete toDelete;
delete nw;
}
//------------------------------------------------------------------
void GraphMaker::checkError(Messaging::msg_script_error &err)
{
GraphError er;
ForIndex(i, m_NodeGraph.nodeWindows.size()){
Node* n = m_NodeGraph.nodeWindows[i]->getNode();
n->setErrorState(false);
}
if (err.code == 0){
//console.clear();
return;
}
if (err.line == -1){ // error line isn't given by IceSL
console.append(err.msg);
return;
}
ForIndex(i, m_NodeGraph.nodeWindows.size()){
Node* n = m_NodeGraph.nodeWindows[i]->getNode();
if (n->isEmitingNode()){
std::vector<Node*> orderedNode;
n->orderNode(orderedNode);
er.computeMap(orderedNode);
Node* nodeErr = er.getNodeByErrorLine(err.line);
nodeErr->setErrorState(true);
console.append(err.msg);
}
}
}
//------------------------------------------------------------------
void GraphMaker::makeNewNode(string path, v2i pos)
{
NodeWindow* n = nullptr;
int s = 0;
string name = project.relativePath(path);
string type = name;
bool isEmitting = false;
name = name.substr(0, name.size() - 4);
if (m_NodeGraph.numberOfWindowsByType.find(type) != m_NodeGraph.numberOfWindowsByType.end()){
s = ++m_NodeGraph.numberOfWindowsByType.at(type);
name = string(name) + std::to_string(s);
} else{
m_NodeGraph.numberOfWindowsByType[type] = 0;
}
n = new NodeWindow(new Node(path, type), name.c_str(), pos);
cerr << name << " is Emitting " << n->getNode()->isEmitingNode() << endl;
if (n != nullptr)m_NodeGraph.nodeWindows.push_back(n);
}
//------------------------------------------------------------------
void GraphMaker::convert_error(Messaging::msg_script_error &err)
{
if (err.code == 1) {
checkError(err);
}
}
//------------------------------------------------------------------
void GraphMaker::saveGraph(string path)
{
GraphSaver::saveGraph(path, m_NodeGraph);
}
//------------------------------------------------------------------
void GraphMaker::loadGraph(string path)
{
GraphSaver::loadGraph(project, path, m_NodeGraph);
this->activeProject = true;
console.clear();
this->onChange();
}
//-------------------------------------
void GraphMaker::RenderMenu()
{
if (ImGui::BeginMainMenuBar())
{
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Quit", "CTRL+W")) {}
ImGui::EndMenu();
}
bool activeProject = hasActiveProject();
if (ImGui::BeginMenu("Project")) {
if (ImGui::MenuItem("New..", "CTRL+N")) {
string path = openPathDialog();
// set current directory to project directory
#ifdef WIN32
SetCurrentDirectoryA(path.c_str());
#else
chdir(path.c_str());
#endif
createProject(path);
}
if (ImGui::MenuItem("Save", "CTRL+S", false, activeProject)) {
saveGraph(getProject().path + "/graph.xml");
}
if (ImGui::MenuItem("Save As..", "", false, activeProject)) {
string path = saveFileDialog("test");
saveGraph(path);
}
if (ImGui::MenuItem("Open", "CTRL+L")) {
string ext = string("Xml graph (*.xml);; All Files (*.*)");
string path = openFileDialog(ext);
// set current directory to project directory
string dir = extractPath(path);
#ifdef WIN32
SetCurrentDirectoryA(dir.c_str());
#else
chdir(dir.c_str());
#endif
loadGraph(path);
}
if (ImGui::MenuItem("Import lua", "CTRL+I")) {
string ext = string("Lua Script (*.lua);; All Files (*.*)");
string path = openFileDialog(ext);
if (strcmp(path.c_str(), "") != 0) {
getProject().importLua(path);
}
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
}
//------------------------------------------------------------------
void GraphMaker::onIdle()
{
ForIndex(i, m_NodeGraph.nodeWindows.size()){
Node* ni = m_NodeGraph.nodeWindows[i]->getNode();
if (ni->hasChange()){
ni->reloadProgram();
console.append(string(ni->getRelativePath() + " reloaded."));
}
}
}
//-------------------------------------
void GraphMaker::renderImgui()
{
bool mouseDown = ImGui::IsMouseClicked(0);
onIdle();
if (m_showRMenu){
if (hasActiveProject()){
string fileName = getProject().renderFileSelecter(m_mousePos);
if (fileName.size() > 0){
makeNewNode(fileName, m_mousePos);
m_showRMenu = false;
}
}
}
RenderMenu();
ForIndex(i, getNodeWindows().size()){
bool toDelete = getNodeWindows()[i]->display();
if (toDelete) {//clicked on the little cross
deleteNodeWindow(getNodeWindows()[i]);
} else {
getNodeWindows()[i]->renderAndPick(m_nodeSelecter, mouseDown);
}
}
//nothing has been picked but mouse was Down
if (mouseDown && (!m_nodeSelecter.outputHasBeenPicked && !m_nodeSelecter.inputHasBeenPicked)){
m_nodeSelecter.reset();
}
m_nodeSelecter.connect();
m_nodeSelecter.outputHasBeenPicked = false;
m_nodeSelecter.inputHasBeenPicked = false;
console.display();
ImGui::Render();
}
//-------------------------------------