forked from jhergel/icesl-nodes
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmain.cpp
More file actions
219 lines (165 loc) · 5.71 KB
/
Copy pathmain.cpp
File metadata and controls
219 lines (165 loc) · 5.71 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
// JH 2017
// SL 2018
#include "remote_handler.h"
#include "graphMaker.h"
#include <LibSL/LibSL.h>
#include <LibSL/LibSL_gl.h>
#include "imgui/imgui.h"
#include "FileDialog.h"
#include "NodeWindow.h"
#include "NodeLua.h"
#include <thread>
#ifdef USE_GLUT
#include <GL/glut.h>
#endif
// --------------------------------------------------------------
LIBSL_WIN32_FIX
using namespace std;
int g_W = 1024;
int g_H = 1024;
// --------------------------------------------------------------
void drawImgUIStuff()
{
GraphMaker::getInstance().renderImgui();
}
// --------------------------------------------------------------
void mainRender()
{
glClearColor(1.0f, 1.0f, 1.0f, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawImgUIStuff();
}
// --------------------------------------------------------------
void mainKeyPressed(uchar k)
{
}
// --------------------------------------------------------------
void mainScanCode(uint sc)
{
}
// --------------------------------------------------------------
void mainScanCodeRelease(uint sc)
{
}
// --------------------------------------------------------------
void mainMousePressed(uint x, uint y, uint button, uint flags)
{
if (flags == LIBSL_BUTTON_DOWN && button == LIBSL_RIGHT_BUTTON) {
GraphMaker::getInstance().setShowRMenu(true);
GraphMaker::getInstance().setMousePos(v2i(x, y));
}
if (GraphMaker::getInstance().isRMenuShown() && flags == LIBSL_BUTTON_DOWN && button == LIBSL_LEFT_BUTTON) {
GraphMaker::getInstance().setShowRMenu(false);
}
}
// --------------------------------------------------------------
void mainMouseMotion(uint x, uint y)
{
}
// --------------------------------------------------------------
void mainMouseWheel(int incr)
{
}
// --------------------------------------------------------------
//TODO WARNING JH: This is here and not in LIBSL because BK can use it without updating LIBSL
//there are some duplicated code
#ifdef USE_GLUT
void mouse(int glut_btn, int glut_state, int x, int y)
{
if ((glut_btn & GLUT_LEFT_BUTTON)
&& (glut_btn & GLUT_RIGHT_BUTTON)) {
glut_btn = GLUT_MIDDLE_BUTTON;
}
uint button = 0, flags = 0;
if (glut_btn == GLUT_LEFT_BUTTON) button = LIBSL_LEFT_BUTTON;
else if (glut_btn == GLUT_MIDDLE_BUTTON) button = LIBSL_MIDDLE_BUTTON;
else if (glut_btn == GLUT_RIGHT_BUTTON) button = LIBSL_RIGHT_BUTTON;
if (glut_state == GLUT_DOWN) {
flags |= LIBSL_BUTTON_DOWN;
} else if (glut_state == GLUT_UP) {
flags |= LIBSL_BUTTON_UP;
}
if ((glut_btn == 3) || (glut_btn == 4)) // It's a wheel event
{
// Each wheel event reports like a button click, GLUT_DOWN then GLUT_UP
if (glut_state == GLUT_UP) return; // Disregard redundant GLUT_UP events
if (glut_btn == 3)SimpleUI::onMouseWheel(1);
if (glut_btn == 4)SimpleUI::onMouseWhefind_package(Qt4 REQUIRED QtCore QtGui)
INCLUDE(${ QT_USE_FILE })el(-1);
return;
}
SimpleUI::onMouseButtonPressed(x, y, button, flags);
}
#endif
// --------------------------------------------------------------
void clientCallback(Messaging::msg_script_error& err)
{
GraphMaker::getInstance().checkError(err);
}
// --------------------------------------------------------------
int main(int argc, char **argv)
{
#ifndef WIN32
int useless = pthread_getconcurrency(); //workaround a bug of ubuntu distrib OLOL
#endif
try {
#ifdef WIN32
// attempts to launch IceSL
vector<string> paths;
paths.push_back(".\\");
paths.push_back(string(LibSL::System::Application::executablePath()) + "\\");
paths.push_back("C:\\Program Files\\INRIA\\IceSL\\bin\\");
paths.push_back("C:\\Program Files (x86)\\INRIA\\IceSL\\bin\\");
ForIndex(i, paths.size()) {
string exe = paths[i] + "IceSL-slicer.exe";
if (exists(exe.c_str())) {
STARTUPINFO si;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
char cmdl[MAX_PATH];
strcpy_s<MAX_PATH>(cmdl, ("\"" + exe + "\" --remote " + GraphMaker::getInstance().masterScriptPath() ).c_str());
BOOL ok = CreateProcessA(exe.c_str(), cmdl, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if (!ok) {
throw Fatal("Cannot launch IceSL.");
} else {
LibSL::System::Process::sleep(2000); // wait a bit for IceSL to init
}
break;
}
}
#endif
// init messaging system
bool ok = Messaging::getInstance().initClient(clientCallback);
if (!ok) {
throw Fatal("Cannot connect to IceSL. Is it running? Was it launched with the --remote flag?");
}
Messaging::getInstance().spawn_client();
// UI
TrackballUI::onRender = mainRender;
TrackballUI::onKeyPressed = mainKeyPressed;
TrackballUI::onMouseButtonPressed = mainMousePressed;
TrackballUI::init(g_W, g_H);
GraphMaker::getInstance().setWindow(g_W, g_H);
// GL
glEnable(GL_DEPTH_TEST);
// imgui
SimpleUI::bindImGui();
TrackballUI::trackball().set(v3f(0), v3f(0), quatf(v3f(1, 0, 0), -1.0f)*quatf(v3f(0, 0, 1), 2.5f));
SimpleUI::initImGui();
SimpleUI::onReshape(g_W, g_H);
// main loop
TrackballUI::loop();
// clean up
// Messaging::getInstance().end_client(); // TODO: proper termination
SimpleUI::terminateImGui();
// shutdown UI
TrackballUI::shutdown();
} catch (Fatal& e) {
cerr << Console::red << e.message() << Console::gray << endl;
return (-1);
}
return 0;
}
// --------------------------------------------------------------