-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelloContext.cpp
99 lines (77 loc) · 1.93 KB
/
HelloContext.cpp
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
#include <sstream>
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
#include <nlohmann/json.hpp>
using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;
using sstream = std::stringstream;
using json = nlohmann::json;
Ptr<Application> app;
Ptr<UserInterface> ui;
bool parse(const char* context, const char *key)
{
bool value;
json parsed;
sstream message;
try {
parsed = json::parse(context);
} catch (json::parse_error &error) {
message << "error while parsing 'context':";
message << std::endl;
message << error.what();
ui->messageBox(message.str(), "Error");
return false;
}
ui->messageBox(parsed.dump(4), "Parsed JSON");
try {
value = parsed.at(key);
} catch (json::out_of_range &error) {
message << "error while accessing 'context':";
message << std::endl;
message << error.what();
ui->messageBox(message.str(), "Error");
return false;
}
message << "context key ";
message << "'" << key << "'";
message << " has value ";
message << std::boolalpha;
message << "'" << value << "'";
ui->messageBox(message.str(), "Success");
return true;
}
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
return parse(context, "IsApplicationStartup");
}
extern "C" XI_EXPORT bool stop(const char* context)
{
if (!app)
return false;
if (!ui)
return false;
return parse(context, "IsApplicationClosing");
}
#ifdef XI_WIN
#include <windows.h>
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif // XI_WIN