382
382
if(val == 0) { // select or deselect everything
383
383
int selectall = 0;
384
for(int i = 0; i < GUI::instance()->visibility->browser->size(); i++)
385
if(!GUI::instance()->visibility->browser->selected(i + 1)) {
384
for(int i = 0; i < FlGui::instance()->visibility->browser->size(); i++)
385
if(!FlGui::instance()->visibility->browser->selected(i + 1)) {
390
for(int i = 0; i < GUI::instance()->visibility->browser->size(); i++)
391
GUI::instance()->visibility->browser->select(i + 1);
390
for(int i = 0; i < FlGui::instance()->visibility->browser->size(); i++)
391
FlGui::instance()->visibility->browser->select(i + 1);
393
GUI::instance()->visibility->browser->deselect();
393
FlGui::instance()->visibility->browser->deselect();
395
395
else if(val == -1){ // invert the selection
396
int *state = new int[GUI::instance()->visibility->browser->size()];
397
for(int i = 0; i < GUI::instance()->visibility->browser->size(); i++)
398
state[i] = GUI::instance()->visibility->browser->selected(i + 1);
399
GUI::instance()->visibility->browser->deselect();
400
for(int i = 0; i < GUI::instance()->visibility->browser->size(); i++)
401
if(!state[i]) GUI::instance()->visibility->browser->select(i + 1);
396
int *state = new int[FlGui::instance()->visibility->browser->size()];
397
for(int i = 0; i < FlGui::instance()->visibility->browser->size(); i++)
398
state[i] = FlGui::instance()->visibility->browser->selected(i + 1);
399
FlGui::instance()->visibility->browser->deselect();
400
for(int i = 0; i < FlGui::instance()->visibility->browser->size(); i++)
401
if(!state[i]) FlGui::instance()->visibility->browser->select(i + 1);
404
404
else if(val == -2){ // create new parameter name for selection
405
for(int i = 0; i < GUI::instance()->visibility->browser->size(); i++){
406
if(GUI::instance()->visibility->browser->selected(i + 1)){
405
for(int i = 0; i < FlGui::instance()->visibility->browser->size(); i++){
406
if(FlGui::instance()->visibility->browser->selected(i + 1)){
407
407
static char tmpstr[256];
408
408
sprintf(tmpstr, "%d", VisibilityList::instance()->getTag(i));
409
GUI::instance()->geoContext->input[1]->value(tmpstr);
409
FlGui::instance()->geoContext->input[1]->value(tmpstr);
413
GUI::instance()->geoContext->input[0]->value("NewName");
414
GUI::instance()->geoContext->show(0);
413
FlGui::instance()->geoContext->input[0]->value("NewName");
414
FlGui::instance()->geoContext->show(0);
416
416
else { // set new sorting mode
417
417
VisibilityList::instance()->setSortMode(val);
443
443
: Fl_Browser(x, y, w, h, c){}
446
#if defined(HAVE_TREE_BROWSER)
446
#if defined(HAVE_FL_TREE)
448
static void _add_vertex(GVertex *gv, Flu_Tree_Browser::Node *n)
448
static void _add_vertex(GVertex *gv, Fl_Tree *tree, std::string path)
451
sprintf(str, "Point %d", gv->tag());
452
Flu_Tree_Browser::Node *n2 = n->add(str);
453
if(gv->getVisibility()) n2->select(true);
454
n2->user_data((void*)gv);
450
std::ostringstream vertex;
451
vertex << path << "Point " << gv->tag() << "/";
452
Fl_Tree_Item *n = tree->add(vertex.str().c_str());
453
if(gv->getVisibility()) n->select(1);
454
n->userdata((void*)gv);
457
static void _add_edge(GEdge *ge, Flu_Tree_Browser::Node *n)
458
static void _add_edge(GEdge *ge, Fl_Tree *tree, std::string path)
460
sprintf(str, "Line %d/", ge->tag());
461
Flu_Tree_Browser::Node *n2 = n->add(str);
462
if(ge->getVisibility()) n2->select(true);
463
n2->user_data((void*)ge);
460
std::ostringstream edge;
461
edge << path << "Line " << ge->tag() << "/";
462
Fl_Tree_Item *n = tree->add(edge.str().c_str());
463
if(ge->getVisibility()) n->select(1);
464
n->userdata((void*)ge);
464
466
if(ge->getBeginVertex())
465
_add_vertex(ge->getBeginVertex(), n2);
467
_add_vertex(ge->getBeginVertex(), tree, edge.str());
466
468
if(ge->getEndVertex())
467
_add_vertex(ge->getEndVertex(), n2);
469
_add_vertex(ge->getEndVertex(), tree, edge.str());
470
static void _add_face(GFace *gf, Flu_Tree_Browser::Node *n)
472
static void _add_face(GFace *gf, Fl_Tree *tree, std::string path)
473
sprintf(str, "Surface %d/", gf->tag());
474
Flu_Tree_Browser::Node *n2 = n->add(str);
475
if(gf->getVisibility()) n2->select(true);
476
n2->user_data((void*)gf);
474
std::ostringstream face;
475
face << path << "Surface " << gf->tag() << "/";
476
Fl_Tree_Item *n = tree->add(face.str().c_str());
477
if(gf->getVisibility()) n->select(1);
478
n->userdata((void*)gf);
477
480
std::list<GEdge*> edges = gf->edges();
478
481
for(std::list<GEdge*>::iterator it = edges.begin(); it != edges.end(); it++)
482
_add_edge(*it, tree, face.str());
482
static void _add_region(GRegion *gr, Flu_Tree_Browser::Node *n)
485
static void _add_region(GRegion *gr, Fl_Tree *tree, std::string path)
485
sprintf(str, "Volume %d/", gr->tag());
486
Flu_Tree_Browser::Node *n2 = n->add(str);
487
if(gr->getVisibility()) n2->select(true);
488
n2->user_data((void*)gr);
487
std::ostringstream region;
488
region << path << "Volume " << gr->tag() << "/";
489
Fl_Tree_Item *n = tree->add(region.str().c_str());
490
if(gr->getVisibility()) n->select(1);
491
n->userdata((void*)gr);
489
493
std::list<GFace*> faces = gr->faces();
490
494
for(std::list<GFace*>::iterator it = faces.begin(); it != faces.end(); it++)
495
_add_face(*it, tree, region.str());
494
498
static void _add_physical_group(int dim, int num, std::vector<GEntity*> &ge,
495
Flu_Tree_Browser::Node *n)
499
std::map<int, std::string> &oldLabels,
500
Fl_Tree *tree, std::string path)
497
502
if(ge.empty()) return;
499
Flu_Tree_Browser::Node *n2 = 0;
501
if(ge[0]->model()->getPhysicalName(num).size())
502
name += std::string(" <<") + ge[0]->model()->getPhysicalName(num) + ">>";
503
std::string name = ge[0]->model()->getPhysicalName(dim, num);
504
if(name.empty() && oldLabels.count(num)) name = oldLabels[num];
505
if(name.size()) name = std::string(" <<") + name + ">>";
508
std::ostringstream group;
505
sprintf(str, "Physical Volume %d%s/", num, name.c_str());
512
group << "Physical Volume " << num << name << "/";
513
n = tree->add(group.str().c_str());
507
515
for(unsigned int i = 0; i < ge.size(); i++)
508
_add_region((GRegion*)ge[i], n2);
516
_add_region((GRegion*)ge[i], tree, group.str());
511
sprintf(str, "Physical Surface %d%s/", num, name.c_str());
519
group << "Physical Surface " << num << name << "/";
520
n = tree->add(group.str().c_str());
513
522
for(unsigned int i = 0; i < ge.size(); i++)
514
_add_face((GFace*)ge[i], n2);
523
_add_face((GFace*)ge[i], tree, group.str());
517
sprintf(str, "Physical Line %d%s/", num, name.c_str());
526
group << "Physical Line " << num << name << "/";
527
n = tree->add(group.str().c_str());
519
529
for(unsigned int i = 0; i < ge.size(); i++)
520
_add_edge((GEdge*)ge[i], n2);
530
_add_edge((GEdge*)ge[i], tree, group.str());
523
sprintf(str, "Physical Point %d%s/", num, name.c_str());
533
group << "Physical Point " << num << name << "/";
534
n = tree->add(group.str().c_str());
525
536
for(unsigned int i = 0; i < ge.size(); i++)
526
_add_vertex((GVertex*)ge[i], n2);
537
_add_vertex((GVertex*)ge[i], tree, group.str());
541
552
GModel::list[i]->getNumVertices();
543
554
if(numEnt > 10000){
544
GUI::instance()->visibility->tree->hide();
545
GUI::instance()->visibility->tree_create->show();
555
FlGui::instance()->visibility->tree->hide();
556
FlGui::instance()->visibility->tree_create->show();
550
GUI::instance()->visibility->tree_create->hide();
551
GUI::instance()->visibility->tree->show();
552
GUI::instance()->visibility->tree->clear();
561
FlGui::instance()->visibility->tree_create->hide();
562
FlGui::instance()->visibility->tree->show();
563
FlGui::instance()->visibility->tree->clear();
555
565
for(unsigned int i = 0; i < GModel::list.size(); i++){
556
566
GModel *m = GModel::list[i];
557
std::string s(" <<");
558
s += m->getName() + ">>";
559
if(m == GModel::current()) s += " (Active)";
560
sprintf(str, "Model [%d] %s/", i, s.c_str());
561
Flu_Tree_Browser::Node *n = GUI::instance()->visibility->tree->add(str);
562
if(m->getVisibility()) n->select(true);
563
Flu_Tree_Browser::Node *e = n->add("Elementary entities/");
567
std::ostringstream model;
568
model << "Model [" << i << "] <<" << m->getName() << ">>";
569
if(m == GModel::current()) model << " (Active)";
573
n = FlGui::instance()->visibility->tree->add(model.str().c_str());
574
if(m->getVisibility()) n->select(1);
577
std::string elementary = model.str() + "Elementary entities/";
578
n = FlGui::instance()->visibility->tree->add(elementary.c_str());
565
581
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
582
_add_region(*it, FlGui::instance()->visibility->tree, elementary);
567
583
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
584
_add_face(*it, FlGui::instance()->visibility->tree, elementary);
569
585
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
586
_add_edge(*it, FlGui::instance()->visibility->tree, elementary);
571
587
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
573
Flu_Tree_Browser::Node *g = n->add("Physical groups/");
588
_add_vertex(*it, FlGui::instance()->visibility->tree, elementary);
590
std::string physical = model.str() + "Physical groups/";
591
n = FlGui::instance()->visibility->tree->add(physical.c_str());
575
594
std::map<int, std::vector<GEntity*> > groups[4];
576
595
m->getPhysicalGroups(groups);
596
std::map<int, std::string> oldLabels;
597
#if !defined(HAVE_NO_PARSER)
598
for(std::map<std::string, std::vector<double> >::iterator it = gmsh_yysymbols.begin();
599
it != gmsh_yysymbols.end(); ++it)
600
for(unsigned int i = 0; i < it->second.size(); i++)
601
oldLabels[(int)it->second[i]] = it->first;
577
603
for(int i = 3; i >= 0; i--)
578
604
for(std::map<int, std::vector<GEntity*> >::iterator it = groups[i].begin();
579
605
it != groups[i].end(); it++)
580
_add_physical_group(i, it->first, it->second, g);
606
_add_physical_group(i, it->first, it->second, oldLabels,
607
FlGui::instance()->visibility->tree, physical);
610
FlGui::instance()->visibility->tree->root_label("Gmsh");
611
FlGui::instance()->visibility->tree->redraw();
584
614
static void build_tree_cb(Fl_Widget *w, void *data)
620
650
static void visibility_tree_apply_cb(Fl_Widget *w, void *data)
622
bool recursive = GUI::instance()->visibility->butt[0]->value() ? true : false;
623
Flu_Tree_Browser::Node *root = GUI::instance()->visibility->tree->first();
652
CTX::instance()->mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
653
bool recursive = FlGui::instance()->visibility->butt[0]->value() ? true : false;
655
Fl_Tree_Item *root = FlGui::instance()->visibility->tree->root();
624
656
for(int i = 0; i < root->children(); i++){
625
657
GModel *m = GModel::list[i];
626
Flu_Tree_Browser::Node *n = root->child(i);
658
Fl_Tree_Item *n = root->child(i);
627
659
// treat special levels separately
629
if(n->selected()){ // if model is selected
661
if(root->is_selected() || n->is_selected()){ // if root or model is selected
630
662
_recur_select(n);
633
665
for(int j = 0; j < n->children(); j++){
634
if(n->child(j)->selected()) // if elementary/physical is selected
666
if(n->child(j)->is_selected()) // if elementary/physical is selected
635
667
_recur_select(n->child(j));
637
669
for(int k = 0; k < n->child(j)->children(); k++){
638
if(n->child(j)->child(k)->selected()) // if physical ent is selected
670
if(n->child(j)->child(k)->is_selected()) // if physical ent is selected
639
671
_recur_select(n->child(j)->child(k));
752
784
bool all = (num < 0) ? true : false;
754
786
GModel *m = GModel::current();
787
std::vector<GEntity*> entities;
788
m->getEntities(entities);
758
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
759
for(unsigned int i = 0; i < (*it)->mesh_vertices.size(); i++)
760
if(all || (*it)->mesh_vertices[i]->getNum() == num)
761
(*it)->mesh_vertices[i]->setVisibility(val);
762
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
763
for(unsigned int i = 0; i < (*it)->mesh_vertices.size(); i++)
764
if(all || (*it)->mesh_vertices[i]->getNum() == num)
765
(*it)->mesh_vertices[i]->setVisibility(val);
766
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
767
for(unsigned int i = 0; i < (*it)->mesh_vertices.size(); i++)
768
if(all || (*it)->mesh_vertices[i]->getNum() == num)
769
(*it)->mesh_vertices[i]->setVisibility(val);
770
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
771
for(unsigned int i = 0; i < (*it)->mesh_vertices.size(); i++)
772
if(all || (*it)->mesh_vertices[i]->getNum() == num)
773
(*it)->mesh_vertices[i]->setVisibility(val);
792
for(unsigned int i = 0; i < entities.size(); i++){
793
for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){
794
MVertex *v = entities[i]->mesh_vertices[j];
795
if(all || v->getNum() == num) v->setVisibility(val);
775
799
case 1: // elements
776
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){
777
for(unsigned int i = 0; i < (*it)->lines.size(); i++)
778
if(all || (*it)->lines[i]->getNum() == num)
779
(*it)->lines[i]->setVisibility(val);
781
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){
782
for(unsigned int i = 0; i < (*it)->triangles.size(); i++)
783
if(all || (*it)->triangles[i]->getNum() == num)
784
(*it)->triangles[i]->setVisibility(val);
785
for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++)
786
if(all || (*it)->quadrangles[i]->getNum() == num)
787
(*it)->quadrangles[i]->setVisibility(val);
789
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){
790
for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++)
791
if(all || (*it)->tetrahedra[i]->getNum() == num)
792
(*it)->tetrahedra[i]->setVisibility(val);
793
for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++)
794
if(all || (*it)->hexahedra[i]->getNum() == num)
795
(*it)->hexahedra[i]->setVisibility(val);
796
for(unsigned int i = 0; i < (*it)->prisms.size(); i++)
797
if(all || (*it)->prisms[i]->getNum() == num)
798
(*it)->prisms[i]->setVisibility(val);
799
for(unsigned int i = 0; i < (*it)->pyramids.size(); i++)
800
if(all || (*it)->pyramids[i]->getNum() == num)
801
(*it)->pyramids[i]->setVisibility(val);
800
for(unsigned int i = 0; i < entities.size(); i++){
801
for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){
802
MElement *e = entities[i]->getMeshElement(j);
803
if(all || e->getNum() == num) e->setVisibility(val);
820
823
case 6: // physical point
821
824
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
822
825
for(unsigned int i = 0; i < (*it)->physicals.size(); i++)
823
if (all || std::abs((*it)->physicals[i]) == num) (*it)->setVisibility(val, recursive);
826
if (all || std::abs((*it)->physicals[i]) == num)
827
(*it)->setVisibility(val, recursive);
825
829
case 7: // physical line
826
830
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
827
831
for(unsigned int i = 0; i < (*it)->physicals.size(); i++)
828
if (all || std::abs((*it)->physicals[i]) == num) (*it)->setVisibility(val, recursive);
832
if (all || std::abs((*it)->physicals[i]) == num)
833
(*it)->setVisibility(val, recursive);
830
835
case 8: // physical surface
831
836
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
832
837
for(unsigned int i = 0; i < (*it)->physicals.size(); i++)
833
if (all || std::abs((*it)->physicals[i]) == num) (*it)->setVisibility(val, recursive);
838
if (all || std::abs((*it)->physicals[i]) == num)
839
(*it)->setVisibility(val, recursive);
835
841
case 9: // physical volume
836
842
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
837
843
for(unsigned int i = 0; i < (*it)->physicals.size(); i++)
838
if (all || std::abs((*it)->physicals[i]) == num) (*it)->setVisibility(val, recursive);
844
if (all || std::abs((*it)->physicals[i]) == num)
845
(*it)->setVisibility(val, recursive);
1017
1024
if(what == ENT_ALL)
1018
1025
CTX::instance()->mesh.changed = ENT_ALL;
1026
drawContext::global()->draw();
1020
1027
Msg::StatusBar(3, false, "Select %s\n[Press %s'q' to abort]",
1021
1028
str.c_str(), mode ? "" : "'u' to undo or ");
1023
char ib = GUI::instance()->selectEntity(what);
1030
char ib = FlGui::instance()->selectEntity(what);
1024
1031
if(ib == 'l') {
1025
1032
// store for possible undo later
1026
vertices = GUI::instance()->selectedVertices;
1027
edges = GUI::instance()->selectedEdges;
1028
faces = GUI::instance()->selectedFaces;
1029
regions = GUI::instance()->selectedRegions;
1030
elements = GUI::instance()->selectedElements;
1033
vertices = FlGui::instance()->selectedVertices;
1034
edges = FlGui::instance()->selectedEdges;
1035
faces = FlGui::instance()->selectedFaces;
1036
regions = FlGui::instance()->selectedRegions;
1037
elements = FlGui::instance()->selectedElements;
1031
1038
_apply_visibility(mode, physical, vertices, edges, faces, regions, elements);
1033
1040
if(ib == 'u' && !mode){ // undo only in hide mode
1049
1056
std::string what = (const char*)data;
1050
1057
if(what == "item"){
1051
drawContext *ctx = GUI::instance()->getCurrentOpenglWindow()->getDrawContext();
1052
for(int i = 0; i < GUI::instance()->visibility->per_window->size(); i++){
1058
drawContext *ctx = FlGui::instance()->getCurrentOpenglWindow()->getDrawContext();
1059
for(unsigned int i = 0;
1060
i < (unsigned int)FlGui::instance()->visibility->per_window->size(); i++){
1053
1061
if(i < GModel::list.size()){
1054
1062
GModel *m = GModel::list[i];
1055
if(GUI::instance()->visibility->per_window->selected(i + 1)) ctx->show(m);
1063
if(FlGui::instance()->visibility->per_window->selected(i + 1)) ctx->show(m);
1056
1064
else ctx->hide(m);
1058
1066
else if(i < GModel::list.size() + PView::list.size()){
1059
1067
PView *v = PView::list[i - GModel::list.size()];
1060
if(GUI::instance()->visibility->per_window->selected(i + 1)) ctx->show(v);
1068
if(FlGui::instance()->visibility->per_window->selected(i + 1)) ctx->show(v);
1061
1069
else ctx->hide(v);
1065
1073
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();
1074
for(unsigned int i = 0; i < FlGui::instance()->graph.size(); i++){
1075
for(unsigned int j = 0; j < FlGui::instance()->graph[i]->gl.size(); j++){
1076
drawContext *ctx = FlGui::instance()->graph[i]->gl[j]->getDrawContext();
1069
1077
ctx->showAll();
1072
for(int i = 0; i < GUI::instance()->visibility->per_window->size(); i++)
1073
GUI::instance()->visibility->per_window->select(i + 1);
1080
for(int i = 0; i < FlGui::instance()->visibility->per_window->size(); i++)
1081
FlGui::instance()->visibility->per_window->select(i + 1);
1083
drawContext::global()->draw();
1078
1086
visibilityWindow::visibilityWindow(int deltaFontSize)
1165
1174
Fl_Group::current()->resizable(g);
1167
#if defined(HAVE_TREE_BROWSER)
1176
#if defined(HAVE_FL_TREE)
1169
1178
Fl_Group *g = new Fl_Group
1170
1179
(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, "Tree browser");
1172
tree = new treeBrowser
1173
(2 * WB, 2 * WB + BH, brw, height - 6 * WB - 3 * BH);
1174
tree->show_root(false);
1175
tree->box(FL_DOWN_BOX);
1176
tree->insertion_mode(FLU_INSERT_BACK);
1177
tree->branch_icons(0, 0);
1178
tree->branch_text(FL_BLACK, FL_HELVETICA_BOLD, FL_NORMAL_SIZE - 1);
1179
tree->leaf_text(FL_BLACK, FL_HELVETICA, FL_NORMAL_SIZE - 1);
1181
tree = new treeBrowser(2 * WB, 2 * WB + BH, brw, height - 6 * WB - 3 * BH);
1182
tree->labelsize(FL_NORMAL_SIZE - 1);
1183
tree->selectmode(FL_TREE_SELECT_MULTI);
1184
tree->connectorstyle(FL_TREE_CONNECTOR_SOLID);
1182
1187
tree_create = new Fl_Button