From 868e14690eca787b0d4663d520a4ac4f272124c9 Mon Sep 17 00:00:00 2001 From: Isaak Lim Date: Thu, 3 Sep 2015 16:04:31 +0000 Subject: [PATCH] added multiple object property visualization support for OVM (thanks to Alexander Dielen) git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@21171 383ad7c9-94d9-4d36-a494-682f7c89f535 --- MultiObjectPropertyModel.cc | 652 ++++++++++++++++++++---------------- MultiObjectPropertyModel.hh | 26 +- PropertyVisPlugin.cc | 228 ++++++------- Utils.hh | 20 +- 4 files changed, 508 insertions(+), 418 deletions(-) diff --git a/MultiObjectPropertyModel.cc b/MultiObjectPropertyModel.cc index 292144f..de57565 100644 --- a/MultiObjectPropertyModel.cc +++ b/MultiObjectPropertyModel.cc @@ -5,8 +5,10 @@ #include "OpenVolumeMesh/OVMPropertyModel.hh" #include "OpenVolumeMesh/Mesh/HexahedralMesh.hh" +#include "Utils.hh" + MultiObjectPropertyModel::MultiObjectPropertyModel(const QStringList& res, QObject *parent) : - PropertyModel(parent), restriction(res), widget(0) + PropertyModel(parent), restriction(res), datatypes(supportedDataTypes()), widget(0) { QVBoxLayout* layout = new QVBoxLayout(); widget = new QWidget(); @@ -15,11 +17,11 @@ MultiObjectPropertyModel::MultiObjectPropertyModel(const QStringList& res, QObje MultiObjectPropertyModel::~MultiObjectPropertyModel() { - for (size_t i = 0; i < propWidgets.size(); ++i) - { - delete propWidgets[i]; - } - delete widget; + for (size_t i = 0; i < propWidgets.size(); ++i) + { + delete propWidgets[i]; + } + delete widget; } QVariant MultiObjectPropertyModel::data(const QModelIndex & index, int role) const @@ -34,364 +36,432 @@ QVariant MultiObjectPropertyModel::data(const QModelIndex & index, int role) con int MultiObjectPropertyModel::rowCount(const QModelIndex & parent) const { - return propNames.size(); + return propNames.size(); } QVariant MultiObjectPropertyModel::headerData(int section, Qt::Orientation orientation, int role) const { - return QVariant::Invalid; + return QVariant::Invalid; } void MultiObjectPropertyModel::objectUpdated() { - using namespace PluginFunctions; - - for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it) - { - // get the property model and call objectUpdated - PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); - if (model == 0) continue; - model->objectUpdated(); - } + using namespace PluginFunctions; + + for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it) + { + // get the property model and call objectUpdated + PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); + if (model == 0) continue; + model->objectUpdated(); + } } void MultiObjectPropertyModel::visualize(QModelIndexList selectedIndices, QWidgetList widgets) { - using namespace PluginFunctions; - - // return if nothing is selected - if (selectedIndices.size() < 1) return; - - for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it) - { - // get the property model and update it - PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); - if (model == 0) continue; - model->gatherProperties(); - - QModelIndexList indexList; - QWidgetList widgetList; - - for (int i = 0; i < selectedIndices.size(); ++i) - { - const QString name = selectedIndices[i].data().toString(); - - // skip this property if it does not exist - const QModelIndex idx = model->indexFromPropName(name); - if (!idx.isValid()) continue; - - // insert items into lists - indexList.append(idx); - widgetList.append(propWidgets[selectedIndices[i].row()]); - } - - // visualize the property - model->visualize(indexList, widgetList); - } + using namespace PluginFunctions; + + // return if nothing is selected + if (selectedIndices.size() < 1) return; + + for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it) + { + // get the property model and update it + PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); + if (model == 0) continue; + model->gatherProperties(); + + QModelIndexList indexList; + QWidgetList widgetList; + + for (int i = 0; i < selectedIndices.size(); ++i) + { + const QString name = selectedIndices[i].data().toString(); + + // skip this property if it does not exist + const QModelIndex idx = model->indexFromPropName(name); + if (!idx.isValid()) continue; + + // insert items into lists + indexList.append(idx); + widgetList.append(propWidgets[selectedIndices[i].row()]); + } + + // visualize the property + model->visualize(indexList, widgetList); + } } void MultiObjectPropertyModel::removeProperty(QModelIndexList selectedIndices) { - using namespace PluginFunctions; - - // return if nothing is selected - if (selectedIndices.size() < 1) return; - - for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it) - { - PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); - if (model == 0) continue; - - QModelIndexList indexList; - - for (int i = 0; i < selectedIndices.size(); ++i) - { - const QString name = selectedIndices[i].data().toString(); - - // skip this property if it does not exist - const QModelIndex idx = model->indexFromPropName(name); - if (!idx.isValid()) continue; - - // insert item into list - indexList.append(idx); - } - - model->removeProperty(indexList); - } - - // update this model - gatherProperties(); + using namespace PluginFunctions; + + // return if nothing is selected + if (selectedIndices.size() < 1) return; + + for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it) + { + PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); + if (model == 0) continue; + + QModelIndexList indexList; + + for (int i = 0; i < selectedIndices.size(); ++i) + { + const QString name = selectedIndices[i].data().toString(); + + // skip this property if it does not exist + const QModelIndex idx = model->indexFromPropName(name); + if (!idx.isValid()) continue; + + // insert item into list + indexList.append(idx); + } + + model->removeProperty(indexList); + } + + // update this model + gatherProperties(); } void MultiObjectPropertyModel::duplicateProperty(QModelIndexList selectedIndices) { - using namespace PluginFunctions; - - // return if nothing is selected - if (selectedIndices.size() < 1) return; - - for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it) - { - PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); - if (model == 0) continue; - - QModelIndexList indexList; - - for (int i = 0; i < selectedIndices.size(); ++i) - { - const QString name = selectedIndices[i].data().toString(); - - // skip this property if it does not exist - const QModelIndex idx = model->indexFromPropName(name); - if (!idx.isValid()) continue; - - // insert item into list - indexList.append(idx); - } - - model->duplicateProperty(indexList); - } - - // update this model - gatherProperties(); + using namespace PluginFunctions; + + // return if nothing is selected + if (selectedIndices.size() < 1) return; + + for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it) + { + PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); + if (model == 0) continue; + + QModelIndexList indexList; + + for (int i = 0; i < selectedIndices.size(); ++i) + { + const QString name = selectedIndices[i].data().toString(); + + // skip this property if it does not exist + const QModelIndex idx = model->indexFromPropName(name); + if (!idx.isValid()) continue; + + // insert item into list + indexList.append(idx); + } + + model->duplicateProperty(indexList); + } + + // update this model + gatherProperties(); } void MultiObjectPropertyModel::gatherProperties() { - using namespace PluginFunctions; - - beginResetModel(); - propNames.clear(); - propInfos.clear(); - for (size_t i = 0; i < propWidgets.size(); ++i) - { - delete propWidgets[i]; - } - propWidgets.clear(); - endResetModel(); - - for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it) - { - PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); - if (model == 0) continue; - model->gatherProperties(); - - for (int i = 0; i < model->rowCount(); ++i) - { - const QModelIndex idx = model->index(i, 0); - const QString name = idx.data().toString(); - - // add property - if (std::find(propNames.begin(), propNames.end(), name) == propNames.end()) - { - PropertyInfo info = model->getPropertyInfo(idx); - QWidget* widget = createWidgetForType(info.typeinfo()); - setRange(info, widget); - - propNames.push_back(name); - propInfos.push_back(info); - propWidgets.push_back(widget); - } - } - } + using namespace PluginFunctions; + + beginResetModel(); + propNames.clear(); + propInfos.clear(); + for (size_t i = 0; i < propWidgets.size(); ++i) + { + delete propWidgets[i]; + } + propWidgets.clear(); + endResetModel(); + + for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it) + { + PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); + if (model == 0) continue; + model->gatherProperties(); + + for (int i = 0; i < model->rowCount(); ++i) + { + const QModelIndex idx = model->index(i, 0); + const QString name = idx.data().toString(); + + // add property + if (std::find(propNames.begin(), propNames.end(), name) == propNames.end()) + { + PropertyInfo info = model->getPropertyInfo(idx); + QWidget* widget = createWidgetForType(info.typeinfo()); + setRange(info, widget); + + propNames.push_back(name); + propInfos.push_back(info); + propWidgets.push_back(widget); + } + } + } } void MultiObjectPropertyModel::clear(QModelIndexList selectedIndices) { - using namespace PluginFunctions; - - // return if nothing is selected - if (selectedIndices.size() < 1) return; - - for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it) - { - PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); - if (model == 0) continue; - - QModelIndexList indexList; - - for (int i = 0; i < selectedIndices.size(); ++i) - { - const QString name = selectedIndices[i].data().toString(); - - // skip this property if it does not exist - const QModelIndex idx = model->indexFromPropName(name); - if (!idx.isValid()) continue; - - // insert item into list - indexList.append(idx); - } - - model->clear(indexList); - } + using namespace PluginFunctions; + + // return if nothing is selected + if (selectedIndices.size() < 1) return; + + for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it) + { + PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id()); + if (model == 0) continue; + + QModelIndexList indexList; + + for (int i = 0; i < selectedIndices.size(); ++i) + { + const QString name = selectedIndices[i].data().toString(); + + // skip this property if it does not exist + const QModelIndex idx = model->indexFromPropName(name); + if (!idx.isValid()) continue; + + // insert item into list + indexList.append(idx); + } + + model->clear(indexList); + } } void MultiObjectPropertyModel::hideWidget() { - widget->hide(); + widget->hide(); } QWidget* MultiObjectPropertyModel::getWidget() { - return widget; + return widget; } void MultiObjectPropertyModel::updateWidget(const QModelIndexList& selectedIndices) { - QLayout* layout = widget->layout(); + QLayout* layout = widget->layout(); for (unsigned int i = 0; i < propWidgets.size(); ++i) { propWidgets[i]->hide(); } - for (int i = 0; i < selectedIndices.size(); ++i) - { - const int row = selectedIndices[i].row(); - QWidget* w = propWidgets[row]; + for (int i = 0; i < selectedIndices.size(); ++i) + { + const int row = selectedIndices[i].row(); + QWidget* w = propWidgets[row]; layout->addWidget(w); w->show(); - } + } widget->setLayout(layout); } void MultiObjectPropertyModel::connectLogs(PropertyVisualizer* propViz) { - + } PropertyInfo MultiObjectPropertyModel::getPropertyInfo(const QModelIndex index) const { - return propInfos[index.row()]; + return propInfos[index.row()]; } QWidget* MultiObjectPropertyModel::createWidgetForType(const TypeInfoWrapper& info) const { - // OpenMesh - // ---------------------------------------- - - if (info == OMPropertyModel::proptype_bool) - return new BooleanWidget(); - if (info == OMPropertyModel::proptype_int) - return new IntegerWidget(); - if (info == OMPropertyModel::proptype_uint) - return new IntegerWidget(); - if (info == OMPropertyModel::proptype_double) - return new DoubleWidget(); - if (info == OMPropertyModel::proptype_Vec3d) - return new VectorWidget; - if (info == OMPropertyModel::proptype_Vec3f) - return new VectorWidget; - if (info == OMPropertyModel::proptype_Vec2d) - return new VectorWidget; - if (info == OMPropertyModel::proptype_Vec2f) - return new VectorWidget; - - #ifdef ENABLE_SKELETON_SUPPORT - if (info == OMPropertyModel::proptype_SkinWeights) - return new SkinWeightsWidget; - #endif - - - // OpenVolumeMesh - // ---------------------------------------- - - if (OVMPropertyModel::isBoolType(info)) - return new BooleanWidget(); - if (OVMPropertyModel::isIntType(info)) - return new IntegerWidget(); - if (OVMPropertyModel::isUnsignedIntType(info)) - return new IntegerWidget(); - if (OVMPropertyModel::isDoubleType(info)) - return new DoubleWidget(); - if (OVMPropertyModel::isVec3dType(info)) - return new VectorWidget(); - if (OVMPropertyModel::isVec3fType(info)) - return new VectorWidget(); - - - // Other - // ---------------------------------------- - - return new QWidget(); + // OpenMesh + // ---------------------------------------- + + if (info == OMPropertyModel::proptype_bool) + return new BooleanWidget(); + if (info == OMPropertyModel::proptype_int) + return new IntegerWidget(); + if (info == OMPropertyModel::proptype_uint) + return new IntegerWidget(); + if (info == OMPropertyModel::proptype_double) + return new DoubleWidget(); + if (info == OMPropertyModel::proptype_Vec3d) + return new VectorWidget; + if (info == OMPropertyModel::proptype_Vec3f) + return new VectorWidget; + if (info == OMPropertyModel::proptype_Vec2d) + return new VectorWidget; + if (info == OMPropertyModel::proptype_Vec2f) + return new VectorWidget; + + #ifdef ENABLE_SKELETON_SUPPORT + if (info == OMPropertyModel::proptype_SkinWeights) + return new SkinWeightsWidget; + #endif + + + // OpenVolumeMesh + // ---------------------------------------- + + if (OVMPropertyModel::isBoolType(info)) + return new BooleanWidget(); + if (OVMPropertyModel::isIntType(info)) + return new IntegerWidget(); + if (OVMPropertyModel::isUnsignedIntType(info)) + return new IntegerWidget(); + if (OVMPropertyModel::isDoubleType(info)) + return new DoubleWidget(); + if (OVMPropertyModel::isVec3dType(info)) + return new VectorWidget(); + if (OVMPropertyModel::isVec3fType(info)) + return new VectorWidget(); + + + // Other + // ---------------------------------------- + + return new QWidget(); } template -void range2(const OpenMesh::BaseKernel* mesh, unsigned int n, const std::string& name, T& min, T& max) +void range3_om(const OpenMesh::BaseKernel* mesh, unsigned int n, const std::string& name, T& min, T& max) { - PropHandle ph; - mesh->get_property_handle(ph, name); - if (!ph.is_valid()) return; - - for (unsigned int i = 0; i < n; ++i) - { - const ItemHandle ih(i); - min = std::min(min, mesh->property(ph, ih)); - max = std::max(max, mesh->property(ph, ih)); - } + PropHandle ph; + mesh->get_property_handle(ph, name); + if (!ph.is_valid()) return; + + for (unsigned int i = 0; i < n; ++i) + { + const ItemHandle ih(i); + min = std::min(min, mesh->property(ph, ih)); + max = std::max(max, mesh->property(ph, ih)); + } +} + +template +void range3_ovm(Property& prop, unsigned int n, T& min, T& max) +{ + for (unsigned int i = 0; i < n; ++i) + { + const ItemHandle ih(i); + min = std::min(min, prop[ih]); + max = std::max(max, prop[ih]); + } +} + +template +void range2_om(const Mesh* mesh, const PropertyInfo& info, T& min, T&max) +{ + if (mesh == 0) return; + + if (info.isVertexProp()) + range3_om, T> + (mesh, mesh->n_vertices(), info.propName(), min, max); + if (info.isHalfedgeProp()) + range3_om, T> + (mesh, mesh->n_halfedges(), info.propName(), min, max); + if (info.isEdgeProp()) + range3_om, T> + (mesh, mesh->n_edges(), info.propName(), min, max); + if (info.isFaceProp()) + range3_om, T> + (mesh, mesh->n_faces(), info.propName(), min, max); +} + +template +void range2_ovm(Mesh* mesh, const PropertyInfo& info, T& min, T&max) +{ + if (mesh == 0) return; + + if (info.isCellProp() && mesh->template cell_property_exists(info.propName())) { + OpenVolumeMesh::CellPropertyT prop = mesh->template request_cell_property(info.propName()); + range3_ovm, T> + (prop, mesh->n_cells(), min, max); + } + if (info.isEdgeProp() && mesh->template edge_property_exists(info.propName())) { + OpenVolumeMesh::EdgePropertyT prop = mesh->template request_edge_property(info.propName()); + range3_ovm, T> + (prop, mesh->n_edges(), min, max); + } + if (info.isFaceProp() && mesh->template face_property_exists(info.propName())) { + OpenVolumeMesh::FacePropertyT prop = mesh->template request_face_property(info.propName()); + range3_ovm, T> + (prop, mesh->n_faces(), min, max); + } + if (info.isHalfedgeProp() && mesh->template halfedge_property_exists(info.propName())) { + OpenVolumeMesh::HalfEdgePropertyT prop = mesh->template request_halfedge_property(info.propName()); + range3_ovm, T> + (prop, mesh->n_halfedges(), min, max); + } + if (info.isHalffaceProp() && mesh->template halfface_property_exists(info.propName())) { + OpenVolumeMesh::HalfFacePropertyT prop = mesh->template request_halfface_property(info.propName()); + range3_ovm, T> + (prop, mesh->n_halffaces(), min, max); + } + if (info.isVertexProp() && mesh->template vertex_property_exists(info.propName())) { + OpenVolumeMesh::VertexPropertyT prop = mesh->template request_vertex_property(info.propName()); + range3_ovm, T> + (prop, mesh->n_vertices(), min, max); + } } template void range1(const BaseObject* obj, const PropertyInfo& info, T& min, T& max) { - using namespace PluginFunctions; - - OpenMesh::BaseKernel* mesh = 0; - if (obj->dataType(DATA_TRIANGLE_MESH)) - mesh = triMesh(obj->id()); - if (obj->dataType(DATA_POLY_MESH)) - mesh = polyMesh(obj->id()); - - if (mesh == 0) return; - - if (info.isVertexProp()) - range2, T> - (mesh, mesh->n_vertices(), info.propName(), min, max); - if (info.isHalfedgeProp()) - range2, T> - (mesh, mesh->n_halfedges(), info.propName(), min, max); - if (info.isEdgeProp()) - range2, T> - (mesh, mesh->n_edges(), info.propName(), min, max); - if (info.isFaceProp()) - range2, T> - (mesh, mesh->n_faces(), info.propName(), min, max); + using namespace PluginFunctions; + + if (obj->dataType(DATA_TRIANGLE_MESH)) + range2_om(triMesh(obj->id()), info, min, max); + if (obj->dataType(DATA_POLY_MESH)) + range2_om(polyMesh(obj->id()), info, min, max); + + #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT + if (obj->dataType(DATA_POLYHEDRAL_MESH)) + range2_ovm(polyhedralMesh(obj->id()), info, min, max); + #endif + + #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT + if (obj->dataType(DATA_HEXAHEDRAL_MESH)) + range2_ovm(hexahedralMesh(obj->id()), info, min, max); + #endif } void MultiObjectPropertyModel::setRange(const PropertyInfo& info, QWidget* widget) const { - using namespace PluginFunctions; - - if (info.typeinfo() == OMPropertyModel::proptype_double) - { - double min = +DBL_MAX; - double max = -DBL_MAX; - - for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it) - { - range1(*o_it, info, min, max); - } - - DoubleWidget* w = static_cast(widget); - w->doubleFixedRange->toggle(); - w->doubleFixedRangeMin->setValue(min); - w->doubleFixedRangeMax->setValue(max); - } - - if (info.typeinfo() == OMPropertyModel::proptype_int) - { - int min = +INT_MAX; - int max = -INT_MAX; - - for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it) - { - range1(*o_it, info, min, max); - } - - IntegerWidget* w = static_cast(widget); - w->intFixedRange->toggle(); - w->intFixedRangeMin->setValue(min); - w->intFixedRangeMax->setValue(max); - } + using namespace PluginFunctions; + + bool isDoubleType = info.typeinfo() == OMPropertyModel::proptype_double; + isDoubleType |= OVMPropertyModel::isDoubleType(info.typeinfo()); + + bool isIntType = info.typeinfo() == OMPropertyModel::proptype_int; + isIntType |= OVMPropertyModel::isIntType(info.typeinfo()); + + + if (isDoubleType) + { + double min = +DBL_MAX; + double max = -DBL_MAX; + + for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it) + { + range1(*o_it, info, min, max); + } + + DoubleWidget* w = static_cast(widget); + w->doubleFixedRange->toggle(); + w->doubleFixedRangeMin->setValue(min); + w->doubleFixedRangeMax->setValue(max); + } + + if (isIntType) + { + int min = +INT_MAX; + int max = -INT_MAX; + + for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it) + { + range1(*o_it, info, min, max); + } + + IntegerWidget* w = static_cast(widget); + w->intFixedRange->toggle(); + w->intFixedRangeMin->setValue(min); + w->intFixedRangeMax->setValue(max); + } } diff --git a/MultiObjectPropertyModel.hh b/MultiObjectPropertyModel.hh index f69f63f..3e477aa 100644 --- a/MultiObjectPropertyModel.hh +++ b/MultiObjectPropertyModel.hh @@ -2,6 +2,7 @@ #define MULTI_OBJECT_PROPERTY_MODEL_H #include "PropertyModel.hh" +#include "OpenFlipper/common/DataTypes.hh" class PropertyVisualizer; @@ -10,11 +11,11 @@ class MultiObjectPropertyModel: public PropertyModel Q_OBJECT public: - MultiObjectPropertyModel(const QStringList& res, QObject *parent = 0); - virtual ~MultiObjectPropertyModel(); + MultiObjectPropertyModel(const QStringList& res, QObject *parent = 0); + virtual ~MultiObjectPropertyModel(); - virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; /// Revisualizes visualized properties. @@ -47,19 +48,20 @@ public: /// Connects the PropertyVisualizer log signals with the log slot. virtual void connectLogs(PropertyVisualizer* propViz); - /// Returns the property info for the property with the given index. - virtual PropertyInfo getPropertyInfo(const QModelIndex index) const; + /// Returns the property info for the property with the given index. + virtual PropertyInfo getPropertyInfo(const QModelIndex index) const; private: - QWidget* createWidgetForType(const TypeInfoWrapper& info) const; - void setRange(const PropertyInfo& info, QWidget* widget) const; + QWidget* createWidgetForType(const TypeInfoWrapper& info) const; + void setRange(const PropertyInfo& info, QWidget* widget) const; private: - const QStringList restriction; + const QStringList restriction; + const DataType datatypes; std::vector propNames; - std::vector propInfos; - std::vector propWidgets; - QWidget* widget; + std::vector propInfos; + std::vector propWidgets; + QWidget* widget; }; #endif /* MULTI_OBJECT_PROPERTY_MODEL_H */ diff --git a/PropertyVisPlugin.cc b/PropertyVisPlugin.cc index 473a994..6c15e9c 100644 --- a/PropertyVisPlugin.cc +++ b/PropertyVisPlugin.cc @@ -76,10 +76,10 @@ #include #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT - #include + #include #endif #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT - #include + #include #endif //== IMPLEMENTATION ========================================================== @@ -94,50 +94,50 @@ propertyModel_(0) void PropertyVisPlugin::initializePlugin() { - if ( OpenFlipper::Options::gui() ) { - tool_ = new PropertyVisToolbar(); + if ( OpenFlipper::Options::gui() ) { + tool_ = new PropertyVisToolbar(); - QSize size(300,300); - tool_->resize(size); + QSize size(300,300); + tool_->resize(size); - tool_->meshNames->setModel(&objectListItemModel_); + tool_->meshNames->setModel(&objectListItemModel_); - emit addHiddenPickMode( PROP_VIS ); + emit addHiddenPickMode( PROP_VIS ); - QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"PropertyVisIcon.png"); + QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"PropertyVisIcon.png"); - emit addToolbox( tr("Property Visualization") , tool_, toolIcon ); - } + emit addToolbox( tr("Property Visualization") , tool_, toolIcon ); + } } //----------------------------------------------------------------------------- -void PropertyVisPlugin::pluginsInitialized() +void PropertyVisPlugin::pluginsInitialized() { - if ( OpenFlipper::Options::gui() ) { + if ( OpenFlipper::Options::gui() ) { - // connect toolbox elements - connect(tool_->meshNames, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotMeshChanged(int) ) ); + // connect toolbox elements + connect(tool_->meshNames, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotMeshChanged(int) ) ); - connect(tool_->visualizeButton, SIGNAL( clicked() ), this, SLOT( slotVisualize() ) ); - connect(tool_->clearButton, SIGNAL( clicked() ), this, SLOT( slotAllCleared() ) ); + connect(tool_->visualizeButton, SIGNAL( clicked() ), this, SLOT( slotVisualize() ) ); + connect(tool_->clearButton, SIGNAL( clicked() ), this, SLOT( slotAllCleared() ) ); - connect(tool_->refresh_property_names_tb, SIGNAL( clicked() ), this, SLOT( slotMeshChanged() ) ); - connect(tool_->duplicate_property_tb, SIGNAL( clicked() ), this, SLOT( slotDuplicateProperty() ) ); - connect(tool_->remove_property_tb, SIGNAL( clicked() ), this, SLOT( slotRemoveProperty() ) ); + connect(tool_->refresh_property_names_tb, SIGNAL( clicked() ), this, SLOT( slotMeshChanged() ) ); + connect(tool_->duplicate_property_tb, SIGNAL( clicked() ), this, SLOT( slotDuplicateProperty() ) ); + connect(tool_->remove_property_tb, SIGNAL( clicked() ), this, SLOT( slotRemoveProperty() ) ); - connect(tool_, SIGNAL( widgetShown() ), this, SLOT( updateGUI() ) ); + connect(tool_, SIGNAL( widgetShown() ), this, SLOT( updateGUI() ) ); - setNewPropertyModel(-1); - } + setNewPropertyModel(-1); + } } //----------------------------------------------------------------------------- void PropertyVisPlugin::slotPickModeChanged( const std::string& _mode) { - if (propertyModel_ != 0) - propertyModel_->pickModeChanged(_mode); + if (propertyModel_ != 0) + propertyModel_->pickModeChanged(_mode); } //----------------------------------------------------------------------------- @@ -146,64 +146,64 @@ void PropertyVisPlugin::slotAllCleared() { using namespace PluginFunctions; - if (propertyModel_ != 0) - { - QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); - propertyModel_->clear(selectedIndices); - propertyModel_->objectUpdated(); - emit updateView(); - } + if (propertyModel_ != 0) + { + QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); + propertyModel_->clear(selectedIndices); + propertyModel_->objectUpdated(); + emit updateView(); + } } //----------------------------------------------------------------------------- void PropertyVisPlugin::objectDeleted(int _id) { - if( OpenFlipper::Options::gui() ) - objectListItemModel_.removeObject(_id); - PropertyModelFactory::Instance().deleteModel(_id); + if( OpenFlipper::Options::gui() ) + objectListItemModel_.removeObject(_id); + PropertyModelFactory::Instance().deleteModel(_id); } //----------------------------------------------------------------------------- void PropertyVisPlugin::slotObjectUpdated( int _identifier, const UpdateType& _type ) { - if( OpenFlipper::Options::gui() ) - { - if ( tool_->isVisible() ) - updateGUI(); - PropertyModel* propertyModel = PropertyModelFactory::Instance().getModel(_identifier); - if (propertyModel) - { - if (_type == UPDATE_ALL) - propertyModel->gatherProperties(); - if (_type == (UPDATE_ALL | UPDATE_GEOMETRY)) - propertyModel->objectUpdated(); - } - } + if( OpenFlipper::Options::gui() ) + { + if ( tool_->isVisible() ) + updateGUI(); + PropertyModel* propertyModel = PropertyModelFactory::Instance().getModel(_identifier); + if (propertyModel) + { + if (_type == UPDATE_ALL) + propertyModel->gatherProperties(); + if (_type == (UPDATE_ALL | UPDATE_GEOMETRY)) + propertyModel->objectUpdated(); + } + } } void PropertyVisPlugin::updateGUI() { - DataType datatype = DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH); + DataType datatype = DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH); #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT - datatype |= DataType(DATA_POLYHEDRAL_MESH); + datatype |= DataType(DATA_POLYHEDRAL_MESH); #endif #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT - datatype |= DataType(DATA_HEXAHEDRAL_MESH); + datatype |= DataType(DATA_HEXAHEDRAL_MESH); #endif - objectListItemModel_.refresh(datatype); + objectListItemModel_.refresh(datatype); } //----------------------------------------------------------------------------- void PropertyVisPlugin::propertySelectionChanged() { - if (propertyModel_ != 0) - { - QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); - propertyModel_->updateWidget(selectedIndices); - } + if (propertyModel_ != 0) + { + QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); + propertyModel_->updateWidget(selectedIndices); + } } //----------------------------------------------------------------------------- @@ -219,40 +219,40 @@ void PropertyVisPlugin::propertySelectionChanged() */ void PropertyVisPlugin::setNewPropertyModel(int id) { - if (propertyModel_) - { - propertyModel_->hideWidget(); - disconnect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString))); - disconnect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString))); - } - propertyModel_ = PropertyModelFactory::Instance().getModel(id); - if (propertyModel_ != 0) - { - - tool_->propertyName_lv->setModel(propertyModel_); - connect(propertyModel_, SIGNAL( modelReset() ), this, SLOT( propertySelectionChanged() )); - connect(tool_->propertyName_lv->selectionModel(), - SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ), - this, - SLOT( propertySelectionChanged() )); - QWidget* widget = propertyModel_->getWidget(); - tool_->propertyWidgets->addWidget(widget); - widget->show(); - propertyModel_->gatherProperties(); - connect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString))); - connect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString))); - } - else - { - tool_->propertyName_lv->setModel(0); - } + if (propertyModel_) + { + propertyModel_->hideWidget(); + disconnect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString))); + disconnect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString))); + } + propertyModel_ = PropertyModelFactory::Instance().getModel(id); + if (propertyModel_ != 0) + { + + tool_->propertyName_lv->setModel(propertyModel_); + connect(propertyModel_, SIGNAL( modelReset() ), this, SLOT( propertySelectionChanged() )); + connect(tool_->propertyName_lv->selectionModel(), + SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ), + this, + SLOT( propertySelectionChanged() )); + QWidget* widget = propertyModel_->getWidget(); + tool_->propertyWidgets->addWidget(widget); + widget->show(); + propertyModel_->gatherProperties(); + connect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString))); + connect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString))); + } + else + { + tool_->propertyName_lv->setModel(0); + } } //----------------------------------------------------------------------------- void PropertyVisPlugin::slotMeshChanged(int /*_index*/) { - int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); + int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); setNewPropertyModel(id); } @@ -261,26 +261,26 @@ void PropertyVisPlugin::slotMeshChanged(int /*_index*/) void PropertyVisPlugin::slotVisualize() { using namespace PluginFunctions; - + // return if nothing is selected if (propertyModel_ == 0) return; int selectedId = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); - + // visualize property propertyModel_->visualize(selectedIndices); - + // emit updates - emit updateView(); - + emit updateView(); + if (selectedId >= 0) { emit updatedObject( selectedId, UPDATE_COLOR ); } else { - ObjectIterator o_it(ALL_OBJECTS, DATA_TRIANGLE_MESH | DATA_POLY_MESH); + ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes()); while (o_it != objectsEnd()) { emit updatedObject( o_it->id(), UPDATE_COLOR ); @@ -292,8 +292,8 @@ void PropertyVisPlugin::slotVisualize() //----------------------------------------------------------------------------- void PropertyVisPlugin::slotMouseEvent( QMouseEvent* _event ) { - if (propertyModel_ != 0) - propertyModel_->mouseEvent(_event); + if (propertyModel_ != 0) + propertyModel_->mouseEvent(_event); } //----------------------------------------------------------------------------- @@ -301,15 +301,15 @@ void PropertyVisPlugin::slotMouseEvent( QMouseEvent* _event ) { void PropertyVisPlugin::slotDuplicateProperty() { using namespace PluginFunctions; - - if (propertyModel_ != 0) - { - QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); - propertyModel_->duplicateProperty(selectedIndices); - emit updateView(); - int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); - slotMeshChanged(); + if (propertyModel_ != 0) + { + QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); + propertyModel_->duplicateProperty(selectedIndices); + + emit updateView(); + int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); + slotMeshChanged(); if (id >= 0) { @@ -317,42 +317,42 @@ void PropertyVisPlugin::slotDuplicateProperty() } else { - ObjectIterator o_it(ALL_OBJECTS, DATA_TRIANGLE_MESH | DATA_POLY_MESH); + ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes()); while (o_it != objectsEnd()) { emit updatedObject( o_it->id(), UPDATE_ALL ); ++o_it; } } - } + } } void PropertyVisPlugin::slotRemoveProperty() { using namespace PluginFunctions; - - if (propertyModel_ != 0) - { - QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); - propertyModel_->removeProperty(selectedIndices); - - emit updateView(); - int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); - + + if (propertyModel_ != 0) + { + QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); + propertyModel_->removeProperty(selectedIndices); + + emit updateView(); + int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); + if (id >= 0) { emit updatedObject( id, UPDATE_ALL ); } else { - ObjectIterator o_it(ALL_OBJECTS, DATA_TRIANGLE_MESH | DATA_POLY_MESH); + ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes()); while (o_it != objectsEnd()) { emit updatedObject( o_it->id(), UPDATE_ALL ); ++o_it; } } - } + } } #if QT_VERSION < 0x050000 diff --git a/Utils.hh b/Utils.hh index db41ab5..2335ef0 100644 --- a/Utils.hh +++ b/Utils.hh @@ -56,9 +56,12 @@ #include #include - #include +#include +#include +#include +#include /*! \class TypeInfoWrapper * \brief Wraps the information of a type. @@ -192,4 +195,19 @@ public: }; +static DataType supportedDataTypes() +{ + DataType res = DATA_TRIANGLE_MESH | DATA_POLY_MESH; + + #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT + res |= DATA_POLYHEDRAL_MESH; + #endif + + #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT + res |= DATA_HEXAHEDRAL_MESH; + #endif + + return res; +} + #endif /* UTILS_H */ -- GitLab