diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Filter_widget.ui b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Filter_widget.ui index 22f95cb2aea..6c77b21c579 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Filter_widget.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Filter_widget.ui @@ -14,18 +14,34 @@ Filter Domain - + - + - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + - plouf + Reset Item + + + diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_filter_domain_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_filter_domain_plugin.cpp index b756b002a1a..0a59c6d2910 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_filter_domain_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_filter_domain_plugin.cpp @@ -75,16 +75,60 @@ public Q_SLOTS: if(!c3t3_item) return; + + for (std::set::iterator it = c3t3_item->subdomain_indices().begin(), + end = c3t3_item->subdomain_indices().end(); it != end; ++it) + { + int index = *it; + QPushButton* button = new QPushButton(tr("%1").arg(index)); + buttons.push_back(button); + button->setCheckable(true); + button->setChecked(true); + QColor color = c3t3_item->getSubdomainIndexColor(index); + QString s("QPushButton { font-weight: bold; background: #" + + QString::number(color.red(),16) + + QString::number(color.green(),16) + + QString::number(color.blue(),16) + + "; }"); + + button->setStyleSheet(s); + connect(button, &QPushButton::toggled, [index, c3t3_item](bool){ + c3t3_item->switchVisibleSubdomain(index); + }); + + dock_widget->horizontalLayout->addWidget(button); + } + + + auto cleanup = [this, c3t3_item](){ + while(!buttons.empty()) + { + auto button = buttons.back(); + buttons.pop_back(); + dock_widget->horizontalLayout->removeWidget(button); + buttons.removeAll(button); + delete button; + } + dock_widget->hide(); + //todo : trouver comment disconnect clean-up, pour pas que ça se connect 36 fois qunad tu appuies sur reset. + std::cout<<"cleaned."<resetButton, &QPushButton::clicked, [this, cleanup](){ + cleanup(); + filter(); + }); + dock_widget->show(); dock_widget->raise(); - - dock_widget->test_label->setText(QString("This item has %1 subdomains.").arg(c3t3_item->subdomain_indices().size())); - } private: QAction* actionFilter; DockWidget* dock_widget; + QVector buttons; + }; #include "Mesh_3_filter_domain_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 145f0d99e27..13361cb672e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -501,6 +502,8 @@ struct Scene_c3t3_item_priv { Tree tree; QVector colors; QVector colors_subdomains; + boost::dynamic_bitset<> visible_subdomain; + bool show_tetrahedra; bool is_aabb_tree_built; bool cnc_are_shown; @@ -659,6 +662,7 @@ Scene_c3t3_item::c3t3_changed() // Fill indices map and get max subdomain value d->surface_patch_indices_.clear(); d->subdomain_indices_.clear(); + d->visible_subdomain.clear(); int max = 0; for (C3t3::Cells_in_complex_iterator cit = this->c3t3().cells_in_complex_begin(), @@ -668,6 +672,7 @@ Scene_c3t3_item::c3t3_changed() d->subdomain_indices_.insert(cit->subdomain_index()); } const int max_subdomain_index = max; + d->visible_subdomain.resize(max_subdomain_index+1, true); for (C3t3::Facets_in_complex_iterator fit = this->c3t3().facets_in_complex_begin(), end = this->c3t3().facets_in_complex_end(); fit != end; ++fit) { @@ -2130,10 +2135,30 @@ std::size_t Scene_c3t3_item::number_of_patches() const return d->surface_patch_indices_.size(); } -std::set Scene_c3t3_item::subdomain_indices() const +const std::set& Scene_c3t3_item::subdomain_indices() const { return d->subdomain_indices_; } +QColor Scene_c3t3_item::getSubdomainIndexColor(int i) const +{ + return d->colors_subdomains[i]; +} + +void Scene_c3t3_item::switchVisibleSubdomain(int i) +{ + d->visible_subdomain[i] = !d->visible_subdomain[i]; + \ + //to remove + if(d->visible_subdomain[i]) + { + std::cout<<"Subdomain "< subdomain_indices() const; + const std::set &subdomain_indices() const; + QColor getSubdomainIndexColor(int i) const; public Q_SLOTS: void on_spheres_color_changed(); @@ -145,6 +146,7 @@ public: void show_grid(bool b); void show_cnc(bool b); + virtual QPixmap graphicalToolTip() const Q_DECL_OVERRIDE; void update_histogram(); @@ -163,6 +165,8 @@ public: void set_detect_borders(bool b); bool get_detect_borders(); + void switchVisibleSubdomain(int); + void itemAboutToBeDestroyed(Scene_item *) Q_DECL_OVERRIDE; void initializeBuffers(Viewer_interface *) const Q_DECL_OVERRIDE;