-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview_measim.cc
132 lines (120 loc) · 3.47 KB
/
view_measim.cc
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
// where the main function is...
#include "measim_run.hh"
#include "sim/gkview.hh"
#include "pot_view.hh"
#include "net_view.hh"
#include "view_misc.hh"
#include "poly_view.hh"
#include "initia_win.hh"
struct Update
{
gltk::Window * w;
double next;
double interval;
Update(gltk::Window * w, double interval) : w(w), next(0), interval(interval) {}
};
std::vector<Update> update_list;
Runnable * sys;
void update_reset()
{
double cnt = sys->count();
for (std::vector<Update>::iterator i = update_list.begin(); i != update_list.end(); i ++) {
i->w->refresh();
i->next = cnt + i->interval;
}
}
void update_views()
{
double cnt = sys->count();
for (std::vector<Update>::iterator i = update_list.begin(); i != update_list.end(); i ++) {
if (cnt < i->next) continue;
i->w->refresh();
i->next += i->interval;
}
}
int main(int argc, char ** argv, char ** envp)
{
gkView view(argc, argv, envp);
MEAsimRun vol;
sys = & vol;
view.set_system(sys);
gltk::Window * w;
view.sys_dashed.connect(sigc::ptr_fun(update_views));
view.set_title("View MEAsim");
PotView pv(& vol);
w = new gltk::Window;
w->add(pv);
pv.show();
w->set_title("W-V space");
w->show();
update_list.push_back(Update(w, 1.0));
NetView nv(& vol);
w = new gltk::Window;
w->add(nv);
nv.show();
w->set_title("network view");
w->show();
update_list.push_back(Update(w, 1.0));
view.tk_changed("range").connect(sigc::mem_fun(mwlist, & std::vector<ModW>::clear));
view.tk_changed("range").connect(sigc::mem_fun(* w, & gltk::Window::refresh));
view.sys_changed.connect(sigc::mem_fun(mwlist, & std::vector<ModW>::clear));
view.sys_changed.connect(sigc::ptr_fun(& update_reset));
PolyView poly(& vol);
w = new gltk::Window;
w->add(poly);
poly.show();
w->set_default_size(800, 320);
w->set_title("firing polygram");
w->show();
update_list.push_back(Update(w, 8.0));
// initia window
InitiaWin ini(vol.get_initia());
view.add_action("Init", sigc::mem_fun(ini, & InitiaWin::show));
view.sys_loaded.connect(sigc::mem_fun(ini, & InitiaWin::sync_mod));
ini.select_ok.connect(sigc::mem_fun(sys, & Runnable::init));
ini.select_ok.connect(sigc::mem_fun(poly, & PolyView::clear));
ini.select_ok.connect(view.sys_changed.make_slot());
return view.execute();
}
/*
* Following is copied from
* http://stackoverflow.com/questions/9555375/qt-cmake-vc-produce-a-command-prompt
*/
#ifdef _WIN32
extern "C" {
#include <shellapi.h>
}
class Win32CommandLineConverter {
private:
std::unique_ptr<char*[]> argv_;
std::vector<std::unique_ptr<char[]>> storage_;
public:
Win32CommandLineConverter()
{
LPWSTR cmd_line = GetCommandLineW();
int argc;
LPWSTR* w_argv = CommandLineToArgvW(cmd_line, &argc);
argv_ = std::unique_ptr<char*[]>(new char*[argc]);
storage_.reserve(argc);
for(int i=0; i<argc; ++i) {
storage_.push_back(ConvertWArg(w_argv[i]));
argv_[i] = storage_.back().get();
}
LocalFree(w_argv);
}
int argc() const {return static_cast<int>(storage_.size());}
char ** argv() const {return argv_.get();}
static std::unique_ptr<char[]> ConvertWArg(LPWSTR w_arg)
{
int size = WideCharToMultiByte(CP_UTF8, 0, w_arg, -1, nullptr, 0, nullptr, nullptr);
std::unique_ptr<char[]> ret(new char[size]);
WideCharToMultiByte(CP_UTF8, 0, w_arg, -1, ret.get(), size, nullptr, nullptr);
return ret;
}
};
int CALLBACK WinMain(HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */)
{
Win32CommandLineConverter cmd_line;
return main(cmd_line.argc(), cmd_line.argv(), 0);
}
#endif