Newer
Older
// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle

Christophe Geuzaine
committed
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@geuz.org>.

Christophe Geuzaine
committed
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
#include <FL/fl_ask.H>
#include "FlGui.h"
#include "drawContext.h"
#include "fileDialogs.h"
#include "optionWindow.h"
#include "pluginWindow.h"
#include "Context.h"
#include "GModel.h"
#include "PView.h"
#include "PViewData.h"
#include "PViewOptions.h"
#include "Options.h"
#include "OpenFile.h"
#include "Field.h"
#include "OS.h"
#include "onelabGroup.h"
#include "viewButton.h"
static void view_toggle_cb(Fl_Widget *w, void *data)
{
int num = (intptr_t)data;
viewButton *but = FlGui::instance()->onelab->getViewButton(num);
if(but){
opt_view_visible(num, GMSH_SET, but->value());
drawContext::global()->draw();
}
}
static void view_reload(int index)
{
if(index >= 0 && index < (int)PView::list.size()){
PView *p = PView::list[index];
if(StatFile(p->getData()->getFileName())){
Msg::Error("File '%s' does not exist", p->getData()->getFileName().c_str());
return;
}
int n = PView::list.size();
// FIXME: use fileIndex
MergeFile(p->getData()->getFileName());
if((int)PView::list.size() > n){ // we loaded a new view
// delete old data and replace with new
delete p->getData();
p->setData(PView::list.back()->getData());
PView::list.back()->setData(0);
// delete new view
delete PView::list.back();
// in case the reloaded view has a different number of time steps
if(p->getOptions()->timeStep > p->getData()->getNumTimeSteps() - 1)
p->getOptions()->timeStep = 0;
p->setChanged(true);
FlGui::instance()->updateViews();
}
}
}
static void view_reload_cb(Fl_Widget *w, void *data)
{
view_reload((intptr_t)data);
drawContext::global()->draw();
}
static void view_reload_all_cb(Fl_Widget *w, void *data)
{
for(unsigned int i = 0; i < PView::list.size(); i++)
view_reload(i);
drawContext::global()->draw();
}
static void view_reload_visible_cb(Fl_Widget *w, void *data)
{
for(unsigned int i = 0; i < PView::list.size(); i++)
if(opt_view_visible(i, GMSH_GET, 0))
view_reload(i);
drawContext::global()->draw();
}
static void view_remove_other_cb(Fl_Widget *w, void *data)
{
if(PView::list.empty()) return;
for(int i = PView::list.size() - 1; i >= 0; i--)
if(i != (intptr_t)data) delete PView::list[i];
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_remove_all_cb(Fl_Widget *w, void *data)
{
if(PView::list.empty()) return;
int mode = (intptr_t)data;
if(mode == -1){ // remove all
if(PView::list.empty()) return;
while(PView::list.size()) delete PView::list[0];
}
else if(mode == -2){ // remove all visible
for(int i = PView::list.size() - 1; i >= 0; i--)
if(opt_view_visible(i, GMSH_GET, 0)) delete PView::list[i];
}
else if(mode == -3){ // remove all invisible
for(int i = PView::list.size() - 1; i >= 0; i--)
if(!opt_view_visible(i, GMSH_GET, 0)) delete PView::list[i];
}
else if(mode == -4){ // remove all empty
for(int i = PView::list.size() - 1; i >= 0; i--)
if(PView::list[i]->getData()->empty()) delete PView::list[i];
}
else if(mode >=0 && mode < (int)PView::list.size()){ // remove by name
std::string name = PView::list[mode]->getData()->getName();
for(int i = PView::list.size() - 1; i >= 0; i--)
if(PView::list[i]->getData()->getName() == name) delete PView::list[i];
}
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_remove_cb(Fl_Widget *w, void *data)
{
delete PView::list[(intptr_t)data];
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
#if defined(HAVE_NATIVE_FILE_CHOOSER)
# define TT "\t"
# define NN "\n"
#else
# define TT " ("
# define NN ")\t"
#endif
static void view_save_cb(Fl_Widget *w, void *data)
{
static const char *formats =
"Gmsh Parsed" TT "*.pos" NN
"Gmsh Mesh-based" TT "*.pos" NN
"Gmsh Legacy ASCII" TT "*.pos" NN
"Gmsh Legacy Binary" TT "*.pos" NN
"MED" TT "*.rmed" NN
"STL Surface" TT "*.stl" NN
"Generic TXT" TT "*.txt" NN;
PView *view = PView::list[(intptr_t)data];
test:
if(fileChooser(FILE_CHOOSER_CREATE, "Save As", formats,
view->getData()->getFileName().c_str())){
std::string name = fileChooserGetName(1);
if(CTX::instance()->confirmOverwrite) {
if(!StatFile(name))
if(!fl_choice("File '%s' already exists.\n\nDo you want to replace it?",
"Cancel", "Replace", 0, name.c_str()))
goto test;
}
int format = 0;
switch(fileChooserGetFilter()){
case 0: format = 2; break;
case 1: format = 5; break;
case 2: format = 0; break;
case 3: format = 1; break;
case 4: format = 6; break;
case 5: format = 3; break;
case 6: format = 4; break;
}
view->write(name, format);
}
}
#undef TT
#undef NN
static void view_alias_cb(Fl_Widget *w, void *data)
{
new PView(PView::list[(intptr_t)data], false);
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_alias_with_options_cb(Fl_Widget *w, void *data)
{
new PView(PView::list[(intptr_t)data], true);
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_combine_space_all_cb(Fl_Widget *w, void *data)
{
PView::combine(false, 1, CTX::instance()->post.combineRemoveOrig);
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_combine_space_visible_cb(Fl_Widget *w, void *data)
{
PView::combine(false, 0, CTX::instance()->post.combineRemoveOrig);
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_combine_space_by_name_cb(Fl_Widget *w, void *data)
{
PView::combine(false, 2, CTX::instance()->post.combineRemoveOrig);
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_combine_time_all_cb(Fl_Widget *w, void *data)
{
PView::combine(true, 1, CTX::instance()->post.combineRemoveOrig);
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_combine_time_visible_cb(Fl_Widget *w, void *data)
{
PView::combine(true, 0, CTX::instance()->post.combineRemoveOrig);
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_combine_time_by_name_cb(Fl_Widget *w, void *data)
{
PView::combine(true, 2, CTX::instance()->post.combineRemoveOrig);
FlGui::instance()->updateViews();
drawContext::global()->draw();
}
static void view_all_visible_cb(Fl_Widget *w, void *data)
{
int mode = (intptr_t)data;
std::string name;
if(mode >= 0) name = PView::list[mode]->getData()->getName();
for(unsigned int i = 0; i < PView::list.size(); i++)
opt_view_visible(i, GMSH_SET | GMSH_GUI,
(mode == -1) ? 1 :
(mode == -2) ? 0 :
(mode == -3) ? !opt_view_visible(i, GMSH_GET, 0) :
(name == PView::list[i]->getData()->getName()) ? 1 :
0);
drawContext::global()->draw();
}
static void view_applybgmesh_cb(Fl_Widget *w, void *data)
{
int index = (intptr_t)data;
if(index >= 0 && index < (int)PView::list.size())
GModel::current()->getFields()->setBackgroundMesh(index);
}
viewButton::viewButton(int x, int y, int w, int h, int num, Fl_Color col)

Christophe Geuzaine
committed
: Fl_Group(x,y,w,h)
{

Christophe Geuzaine
committed
PView *view = PView::list[num];
PViewData *data = view->getData();
PViewOptions *opt = view->getOptions();
_toggle = new Fl_Check_Button(x, y, w - popw, h);
_toggle->box(FL_FLAT_BOX);
_toggle->color(col);

Christophe Geuzaine
committed
_toggle->callback(view_toggle_cb, (void *)num);
_toggle->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);

Christophe Geuzaine
committed
_toggle->value(opt->visible);
char tmp[256];
sprintf(tmp, "[%d] %s", num, data->getName().c_str());
_toggle->copy_label(tmp);

Christophe Geuzaine
committed
strcpy(_tooltip, data->getFileName().c_str());
_toggle->tooltip(_tooltip);

Christophe Geuzaine
committed
_butt->align(FL_ALIGN_RIGHT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
_butt->tooltip("Show view option menu (Shift+w)");
_butt->box(FL_FLAT_BOX);
_butt->color(col);
_butt->selection_color(col);

Christophe Geuzaine
committed
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
_popup = new Fl_Menu_Button(x + w - popw, y, popw, h);
_popup->type(Fl_Menu_Button::POPUP123);
_popup->add("Reload/View", 'r',
(Fl_Callback *) view_reload_cb, (void *)num, 0);
_popup->add("Reload/Visible Views", 0,
(Fl_Callback *) view_reload_visible_cb, (void *)num, 0);
_popup->add("Reload/All Views", 0,
(Fl_Callback *) view_reload_all_cb, (void *)num, 0);
_popup->add("Remove/View", FL_Delete,
(Fl_Callback *) view_remove_cb, (void *)num, 0);
_popup->add("Remove/Other Views", 0,
(Fl_Callback *) view_remove_other_cb, (void *)num, 0);
_popup->add("Remove/Visible Views", 0,
(Fl_Callback *) view_remove_all_cb, (void *)-2, 0);
_popup->add("Remove/Invisible Views", 0,
(Fl_Callback *) view_remove_all_cb, (void *)-3, 0);
_popup->add("Remove/Empty Views", 0,
(Fl_Callback *) view_remove_all_cb, (void *)-4, 0);
_popup->add("Remove/All Views", 0,
(Fl_Callback *) view_remove_all_cb, (void *)-1, 0);
_popup->add("Remove/By Name", 0,
(Fl_Callback *) view_remove_all_cb, (void *)num, 0);
_popup->add("Alias/View without Options", 0,
(Fl_Callback *) view_alias_cb, (void *)num, 0);
_popup->add("Alias/View with Options", 0,
(Fl_Callback *) view_alias_with_options_cb, (void *)num, 0);
_popup->add("Combine Elements/From Visible Views", 0,
(Fl_Callback *) view_combine_space_visible_cb, (void *)num, 0);
_popup->add("Combine Elements/From All Views", 0,
(Fl_Callback *) view_combine_space_all_cb, (void *)num, 0);
_popup->add("Combine Elements/By View Name", 0,
(Fl_Callback *) view_combine_space_by_name_cb, (void *)num, 0);
_popup->add("Combine Time Steps/From Visible Views", 0,
(Fl_Callback *) view_combine_time_visible_cb, (void *)num, 0);
_popup->add("Combine Time Steps/From All Views", 0,
(Fl_Callback *) view_combine_time_all_cb, (void *)num, 0);
_popup->add("Combine Time Steps/By View Name", 0,
(Fl_Callback *) view_combine_time_by_name_cb, (void *)num, 0);
_popup->add("Set Visibility/All On", 0,
(Fl_Callback *) view_all_visible_cb, (void *)-1, 0);
_popup->add("Set Visibility/All Off", 0,
(Fl_Callback *) view_all_visible_cb, (void *)-2, 0);
_popup->add("Set Visibility/Invert", 0,
(Fl_Callback *) view_all_visible_cb, (void *)-3, 0);
_popup->add("Set Visibility/By name", 0,
(Fl_Callback *) view_all_visible_cb, (void *)num, 0);
_popup->add("Apply As Background Mesh", 0,
(Fl_Callback *) view_applybgmesh_cb, (void *)num, 0);
_popup->add("Save As...", 0,
(Fl_Callback *) view_save_cb, (void *)num, FL_MENU_DIVIDER);
_popup->add("Options", 'o',
(Fl_Callback *) view_options_cb, (void *)num, 0);
_popup->add("Plugins", 'p',
(Fl_Callback *) plugin_cb, (void *)num, 0);
end(); // close the group
resizable(_toggle);
}