16
17
#include "visibilityWindow.h"
17
18
#include "paletteWindow.h"
18
19
#include "contextWindow.h"
20
#include "graphicWindow.h"
19
21
#include "GmshDefines.h"
20
22
#include "GmshMessage.h"
21
23
#include "GModel.h"
22
24
#include "MElement.h"
26
#include "PViewData.h"
23
27
#include "GeoStringInterface.h"
24
28
#include "Options.h"
25
29
#include "Context.h"
188
190
_entities.push_back(new VisModel(GModel::list[i], i));
189
191
std::string name = GModel::list[i]->getName();
190
192
if(GModel::list[i] == GModel::current()) name += " (Active)";
193
setLabel(i, name, 1);
194
if(type == ElementaryEntities){
196
else if(type == ElementaryEntities){
195
197
for(GModel::piter it = m->firstElementaryName(); it != m->lastElementaryName(); ++it)
196
setLabel(it->first, it->second);
198
setLabel(it->first, it->second, 1);
197
199
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
198
200
_entities.push_back(new VisElementary(*it));
199
201
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
206
208
else if(type == PhysicalEntities){
207
209
for(GModel::piter it = m->firstPhysicalName(); it != m->lastPhysicalName(); ++it)
208
setLabel(it->first, it->second);
210
setLabel(it->first, it->second, 1);
209
211
std::map<int, std::vector<GEntity*> > groups[4];
210
212
m->getPhysicalGroups(groups);
211
213
for(int i = 0; i < 4; i++){
260
262
std::string getBrowserLine(int n)
262
264
int tag = _entities[n]->getTag();
264
bool label_exists = _labels.count(tag);
265
const char *label_color = (label_exists && _labels[tag].second) ? "@b" : "";
266
sprintf(str, "\t%s\t%d\t%s%s", _entities[n]->getName().c_str(), tag,
267
label_color, label_exists ? _labels[tag].first.c_str() : "");
268
return std::string(str);
265
std::ostringstream sstream;
266
sstream << "\t" << _entities[n]->getName() << "\t" << tag << "\t";
267
if(_labels.count(tag)){
268
if(_labels[tag].second)
270
sstream << _labels[tag].first;
272
return sstream.str();
270
274
// set the sort mode
271
275
void setSortMode(int mode){ _sortMode = (_sortMode != mode) ? mode : -mode; }
272
276
// get the sort mode
273
277
int getSortMode(){ return _sortMode; }
274
278
// associate a label with a tag (quality=0 for "old-style" unreliable labels)
275
void setLabel(int tag, std::string label, int quality=1)
279
void setLabel(int tag, std::string label, int quality)
277
_labels[tag] = std::make_pair(label, quality);
281
if(label.size()) _labels[tag] = std::pair<std::string, int>(label, quality);
279
283
// get the label associated with a tag
280
284
std::string getLabel(int tag){ return _labels[tag].first; }
314
318
// if the browser is not empty, get the selections made in the
315
319
// browser and apply them into the model
316
320
if(VisibilityList::instance()->getNumEntities()){
317
CTX.mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
321
CTX::instance()->mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
318
322
bool recursive = GUI::instance()->visibility->butt[0]->value() ? true : false;
319
323
VisibilityList::VisibilityType type;
320
324
switch(GUI::instance()->visibility->browser_type->value()){
553
557
std::string s(" <<");
554
558
s += m->getName() + ">>";
555
559
if(m == GModel::current()) s += " (Active)";
556
sprintf(str, "Model %d %s/", i, s.c_str());
560
sprintf(str, "Model [%d] %s/", i, s.c_str());
557
561
Flu_Tree_Browser::Node *n = GUI::instance()->visibility->tree->add(str);
558
562
if(m->getVisibility()) n->select(true);
559
563
Flu_Tree_Browser::Node *e = n->add("Elementary entities/");
686
690
#if defined(HAVE_TREE_BROWSER)
687
691
_rebuild_tree_browser(false);
693
GUI::instance()->visibility->updatePerWindow(true);
691
696
static void visibility_save_cb(Fl_Widget *w, void *data)
845
850
bool recursive = GUI::instance()->visibility->butt[0]->value() ? true : false;
847
852
if(mode == 1){ // when showing a single entity, first hide everything
848
if(CTX.pick_elements)
853
if(CTX::instance()->pickElements)
849
854
_set_visibility_by_number(1, -1, 0, false);
851
856
for(int i = 2; i <= 5; i++)
896
901
static void visibility_number_cb(Fl_Widget *w, void *data)
898
CTX.mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
903
CTX::instance()->mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
900
905
// what = 0 for nodes, 1 for elements, 2 for points, 3 for lines, 4
901
906
// for surfaces, 5 for volumes, 6 for physical points, 7 for
931
936
bool physical = (str.find("physical") != std::string::npos);
933
938
if(str == "elements to hide"){
934
CTX.pick_elements = 1;
939
CTX::instance()->pickElements = 1;
938
943
else if(str == "points to hide" || str == "physical points to hide"){
939
CTX.pick_elements = 0;
944
CTX::instance()->pickElements = 0;
940
945
what = ENT_POINT;
942
947
opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1);
944
949
else if(str == "lines to hide" || str == "physical lines to hide"){
945
CTX.pick_elements = 0;
950
CTX::instance()->pickElements = 0;
948
953
opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1);
950
955
else if(str == "surfaces to hide" || str == "physical surfaces to hide"){
951
CTX.pick_elements = 0;
956
CTX::instance()->pickElements = 0;
952
957
what = ENT_SURFACE;
954
959
if(GModel::current()->getMeshStatus() < 2)
955
960
opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1);
957
962
else if(str == "volumes to hide" || str == "physical volumes to hide"){
958
CTX.pick_elements = 0;
963
CTX::instance()->pickElements = 0;
959
964
what = ENT_VOLUME;
961
966
if(GModel::current()->getMeshStatus() < 3)
962
967
opt_geometry_volumes(0, GMSH_SET | GMSH_GUI, 1);
964
969
else if(str == "elements to show"){
965
CTX.pick_elements = 1;
970
CTX::instance()->pickElements = 1;
969
974
else if(str == "points to show" || str == "physical points to show"){
970
CTX.pick_elements = 0;
975
CTX::instance()->pickElements = 0;
971
976
what = ENT_POINT;
973
978
opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1);
975
980
else if(str == "lines to show" || str == "physical lines to show"){
976
CTX.pick_elements = 0;
981
CTX::instance()->pickElements = 0;
979
984
opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1);
981
986
else if(str == "surfaces to show" || str == "physical surfaces to show"){
982
CTX.pick_elements = 0;
987
CTX::instance()->pickElements = 0;
983
988
what = ENT_SURFACE;
985
990
if(GModel::current()->getMeshStatus() < 2)
986
991
opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1);
988
993
else if(str == "volumes to show" || str == "physical volumes to show"){
989
CTX.pick_elements = 0;
994
CTX::instance()->pickElements = 0;
990
995
what = ENT_VOLUME;
992
997
if(GModel::current()->getMeshStatus() < 3)
995
1000
else if(str == "show all"){
996
1001
for(int i = 1; i <= 5; i++) // elements, points, lines, surfaces, volumes
997
1002
_set_visibility_by_number(i, -1, 1, false);
998
CTX.mesh.changed = ENT_ALL;
1003
CTX::instance()->mesh.changed = ENT_ALL;
1012
1017
if(what == ENT_ALL)
1013
CTX.mesh.changed = ENT_ALL;
1018
CTX::instance()->mesh.changed = ENT_ALL;
1015
1020
Msg::StatusBar(3, false, "Select %s\n[Press %s'q' to abort]",
1016
1021
str.c_str(), mode ? "" : "'u' to undo or ");
1036
CTX.mesh.changed = ENT_ALL;
1037
CTX.pick_elements = 0;
1041
CTX::instance()->mesh.changed = ENT_ALL;
1042
CTX::instance()->pickElements = 0;
1039
1044
Msg::StatusBar(3, false, "");
1047
static void visibility_per_window_cb(Fl_Widget *w, void *data)
1049
std::string what = (const char*)data;
1051
drawContext *ctx = GUI::instance()->getCurrentOpenglWindow()->getDrawContext();
1052
for(int i = 0; i < GUI::instance()->visibility->per_window->size(); i++){
1053
if(i < GModel::list.size()){
1054
GModel *m = GModel::list[i];
1055
if(GUI::instance()->visibility->per_window->selected(i + 1)) ctx->show(m);
1058
else if(i < GModel::list.size() + PView::list.size()){
1059
PView *v = PView::list[i - GModel::list.size()];
1060
if(GUI::instance()->visibility->per_window->selected(i + 1)) ctx->show(v);
1065
else if(what == "reset_all"){
1066
for(unsigned int i = 0; i < GUI::instance()->graph.size(); i++){
1067
for(unsigned int j = 0; j < GUI::instance()->graph[i]->gl.size(); j++){
1068
drawContext *ctx = GUI::instance()->graph[i]->gl[j]->getDrawContext();
1072
for(int i = 0; i < GUI::instance()->visibility->per_window->size(); i++)
1073
GUI::instance()->visibility->per_window->select(i + 1);
1042
1078
visibilityWindow::visibilityWindow(int deltaFontSize)
1044
1080
FL_NORMAL_SIZE -= deltaFontSize;
1049
1085
int brw = width - 4 * WB;
1051
1087
win = new paletteWindow
1052
(width, height, CTX.non_modal_windows ? true : false, "Visibility");
1088
(width, height, CTX::instance()->nonModalWindows ? true : false, "Visibility");
1053
1089
win->box(GMSH_WINDOW_BOX);
1055
1091
Fl_Tabs *o = new Fl_Tabs
1141
1177
tree->branch_icons(0, 0);
1142
1178
tree->branch_text(FL_BLACK, FL_HELVETICA_BOLD, FL_NORMAL_SIZE - 1);
1143
1179
tree->leaf_text(FL_BLACK, FL_HELVETICA, FL_NORMAL_SIZE - 1);
1144
Fl_Group::current()->resizable(tree);
1147
1182
tree_create = new Fl_Button
1166
1202
int yy = 2 * WB + BH;
1167
1203
for(int i = 0; i < 10; i++){
1169
Fl_Box *b = new Fl_Box(2 * WB, yy, IW, BH, "Mesh entities:");
1205
Fl_Box *b = new Fl_Box(2 * WB, yy, IW, BH, "Mesh:");
1206
b->labelfont(FL_BOLD);
1170
1207
b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
1173
1210
else if(i == 2){
1174
1211
Fl_Box *b = new Fl_Box(2 * WB, yy, IW, BH, "Elementary entities:");
1212
b->labelfont(FL_BOLD);
1175
1213
b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
1178
1216
else if(i == 6){
1179
1217
Fl_Box *b = new Fl_Box(2 * WB, yy, IW, BH, "Physical groups:");
1218
b->labelfont(FL_BOLD);
1180
1219
b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
1235
1274
int yy = 2 * WB + BH;
1236
1275
for(int i = 0; i < 9; i++){
1238
Fl_Box *b = new Fl_Box(2 * WB, yy, IW, BH, "Mesh entities:");
1277
Fl_Box *b = new Fl_Box(2 * WB, yy, IW, BH, "Mesh:");
1278
b->labelfont(FL_BOLD);
1239
1279
b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
1242
1282
else if(i == 1){
1243
1283
Fl_Box *b = new Fl_Box(2 * WB, yy, IW, BH, "Elementary entities:");
1284
b->labelfont(FL_BOLD);
1244
1285
b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
1247
1288
else if(i == 5){
1248
1289
Fl_Box *b = new Fl_Box(2 * WB, yy, IW, BH, "Physical groups:");
1290
b->labelfont(FL_BOLD);
1249
1291
b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
1342
Fl_Group *g = new Fl_Group
1343
(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, "Per window");
1346
per_window = new Fl_Multi_Browser
1347
(2 * WB, 2 * WB + BH, brw, height - 6 * WB - 3 * BH);
1348
per_window->callback(visibility_per_window_cb, (void*)"item");
1350
Fl_Button *b1 = new Fl_Button
1351
(width - 1 * BB - 2 * WB, height - 2 * BH - 3 * WB, BB, BH, "Reset all");
1352
b1->callback(visibility_per_window_cb, (void*)"reset_all");
1354
g->resizable(per_window);
1301
1359
win->resizable(o);
1313
1371
o1->callback(visibility_save_cb);
1316
win->position(CTX.vis_position[0], CTX.vis_position[1]);
1374
win->position(CTX::instance()->visPosition[0], CTX::instance()->visPosition[1]);
1319
1377
FL_NORMAL_SIZE += deltaFontSize;
1388
void visibilityWindow::updatePerWindow(bool force)
1390
static openglWindow *gl = 0;
1391
if(!force && gl == GUI::instance()->getCurrentOpenglWindow()) return;
1393
gl = GUI::instance()->getCurrentOpenglWindow();
1394
drawContext *ctx = gl->getDrawContext();
1396
per_window->clear();
1399
for(unsigned int i = 0; i < GModel::list.size(); i++){
1400
GModel *m = GModel::list[i];
1401
std::ostringstream sstream;
1402
sstream << "Model [" << i << "] <<" << m->getName() << ">>";
1403
per_window->add(sstream.str().c_str());
1404
if(ctx->isVisible(m))
1405
per_window->select(line, 1);
1409
for(unsigned int i = 0; i < PView::list.size(); i++){
1410
PView *v = PView::list[i];
1411
std::ostringstream sstream;
1412
sstream << "View [" << i << "] <<" << v->getData()->getName() << ">>";
1413
per_window->add(sstream.str().c_str());
1414
if(ctx->isVisible(v))
1415
per_window->select(line, 1);