50 #include "MultiObjectPropertyModel.hh"
52 #include "PropertyModelFactory.hh"
53 #include "OpenMesh/OMPropertyModel.hh"
54 #include "OpenVolumeMesh/OVMPropertyModel.hh"
56 MultiObjectPropertyModel::MultiObjectPropertyModel(
const QStringList& res, QObject *parent) :
57 PropertyModel(parent), restriction(res), datatypes(supportedDataTypes()), widget(0)
59 QVBoxLayout* layout =
new QVBoxLayout();
60 widget =
new QWidget();
61 widget->setLayout(layout);
64 MultiObjectPropertyModel::~MultiObjectPropertyModel()
66 for (
size_t i = 0; i < propWidgets.size(); ++i)
68 delete propWidgets[i];
73 QVariant MultiObjectPropertyModel::data(
const QModelIndex & index,
int role)
const
77 return QVariant(propNames[index.row()]);
79 return QVariant::Invalid;
83 int MultiObjectPropertyModel::rowCount(
const QModelIndex & parent)
const
85 return propNames.size();
88 QVariant MultiObjectPropertyModel::headerData(
int section, Qt::Orientation orientation,
int role)
const
90 return QVariant::Invalid;
101 if (model == 0)
continue;
111 if (selectedIndices.size() < 1)
return;
117 if (model == 0)
continue;
120 QModelIndexList indexList;
121 QWidgetList widgetList;
123 for (
int i = 0; i < selectedIndices.size(); ++i)
125 const QString name = selectedIndices[i].data().toString();
129 if (!idx.isValid())
continue;
132 indexList.append(idx);
133 widgetList.append(propWidgets[selectedIndices[i].row()]);
146 if (selectedIndices.size() < 1)
return;
151 if (model == 0)
continue;
153 QModelIndexList indexList;
155 for (
int i = 0; i < selectedIndices.size(); ++i)
157 const QString name = selectedIndices[i].data().toString();
161 if (!idx.isValid())
continue;
164 indexList.append(idx);
179 if (selectedIndices.size() < 1)
return;
184 if (model == 0)
continue;
186 QModelIndexList indexList;
188 for (
int i = 0; i < selectedIndices.size(); ++i)
190 const QString name = selectedIndices[i].data().toString();
194 if (!idx.isValid())
continue;
197 indexList.append(idx);
214 for (
size_t i = 0; i < propWidgets.size(); ++i)
216 delete propWidgets[i];
224 if (model == 0)
continue;
227 for (
int i = 0; i < model->rowCount(); ++i)
229 const QModelIndex idx = model->index(i, 0);
230 const QString name = idx.data().toString();
233 if (std::find(propNames.begin(), propNames.end(), name) == propNames.end())
236 QWidget* widget = createWidgetForType(info.typeinfo());
237 setRange(info, widget);
239 propNames.push_back(name);
240 propInfos.push_back(info);
241 propWidgets.push_back(widget);
252 if (selectedIndices.size() < 1)
return;
257 if (model == 0)
continue;
259 QModelIndexList indexList;
261 for (
int i = 0; i < selectedIndices.size(); ++i)
263 const QString name = selectedIndices[i].data().toString();
267 if (!idx.isValid())
continue;
270 indexList.append(idx);
273 model->
clear(indexList);
289 QLayout* layout = widget->layout();
291 for (
unsigned int i = 0; i < propWidgets.size(); ++i)
293 propWidgets[i]->hide();
296 for (
int i = 0; i < selectedIndices.size(); ++i)
298 const int row = selectedIndices[i].row();
299 QWidget* w = propWidgets[row];
300 layout->addWidget(w);
304 widget->setLayout(layout);
314 return propInfos[index.row()];
317 QWidget* MultiObjectPropertyModel::createWidgetForType(
const TypeInfoWrapper& info)
const
323 return new BooleanWidget();
325 return new IntegerWidget();
327 return new IntegerWidget();
329 return new DoubleWidget();
331 return new VectorWidget;
333 return new VectorWidget;
335 return new VectorWidget;
337 return new VectorWidget;
339 #ifdef ENABLE_SKELETON_SUPPORT
341 return new SkinWeightsWidget;
348 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
349 if (OVMPropertyModel<HexahedralMesh>::isBoolType(info))
350 return new BooleanWidget();
351 if (OVMPropertyModel<HexahedralMesh>::isIntType(info))
352 return new IntegerWidget();
353 if (OVMPropertyModel<HexahedralMesh>::isUnsignedIntType(info))
354 return new IntegerWidget();
355 if (OVMPropertyModel<HexahedralMesh>::isDoubleType(info))
356 return new DoubleWidget();
357 if (OVMPropertyModel<HexahedralMesh>::isVec3dType(info))
358 return new VectorWidget();
359 if (OVMPropertyModel<HexahedralMesh>::isVec3fType(info))
360 return new VectorWidget();
367 return new QWidget();
370 template <
typename ItemHandle,
typename PropHandle,
typename T>
371 void range3_om(
const OpenMesh::BaseKernel* mesh,
unsigned int n,
const std::string& name, T& min, T& max)
375 if (!ph.is_valid())
return;
377 for (
unsigned int i = 0; i < n; ++i)
379 const ItemHandle ih(i);
380 min = std::min(min, mesh->
property(ph, ih));
381 max = std::max(max, mesh->
property(ph, ih));
385 template <
typename ItemHandle,
typename Property,
typename T>
386 void range3_ovm(Property& prop,
unsigned int n, T& min, T& max)
388 for (
unsigned int i = 0; i < n; ++i)
390 const ItemHandle ih(i);
391 min = std::min(min, prop[ih]);
392 max = std::max(max, prop[ih]);
396 template <
typename Mesh,
typename T>
399 if (mesh == 0)
return;
401 if (info.isVertexProp())
403 (mesh, mesh->n_vertices(), info.propName(), min, max);
404 if (info.isHalfedgeProp())
406 (mesh, mesh->n_halfedges(), info.propName(), min, max);
407 if (info.isEdgeProp())
409 (mesh, mesh->n_edges(), info.propName(), min, max);
410 if (info.isFaceProp())
412 (mesh, mesh->n_faces(), info.propName(), min, max);
415 template <
typename Mesh,
typename T>
418 if (mesh == 0)
return;
420 if (info.isCellProp() && mesh->template cell_property_exists<T>(info.propName())) {
422 range3_ovm<OpenVolumeMesh::CellHandle, OpenVolumeMesh::CellPropertyT<T>, T>
423 (prop, mesh->n_cells(), min, max);
425 if (info.isEdgeProp() && mesh->template edge_property_exists<T>(info.propName())) {
427 range3_ovm<OpenVolumeMesh::EdgeHandle, OpenVolumeMesh::EdgePropertyT<T>, T>
428 (prop, mesh->n_edges(), min, max);
430 if (info.isFaceProp() && mesh->template face_property_exists<T>(info.propName())) {
432 range3_ovm<OpenVolumeMesh::FaceHandle, OpenVolumeMesh::FacePropertyT<T>, T>
433 (prop, mesh->n_faces(), min, max);
435 if (info.isHalfedgeProp() && mesh->template halfedge_property_exists<T>(info.propName())) {
437 range3_ovm<OpenVolumeMesh::HalfEdgeHandle, OpenVolumeMesh::HalfEdgePropertyT<T>, T>
438 (prop, mesh->n_halfedges(), min, max);
440 if (info.isHalffaceProp() && mesh->template halfface_property_exists<T>(info.propName())) {
442 range3_ovm<OpenVolumeMesh::HalfFaceHandle, OpenVolumeMesh::HalfFacePropertyT<T>, T>
443 (prop, mesh->n_halffaces(), min, max);
445 if (info.isVertexProp() && mesh->template vertex_property_exists<T>(info.propName())) {
447 range3_ovm<OpenVolumeMesh::VertexHandle, OpenVolumeMesh::VertexPropertyT<T>, T>
448 (prop, mesh->n_vertices(), min, max);
452 template <
typename T>
458 range2_om(
triMesh(obj->
id()), info, min, max);
460 range2_om(
polyMesh(obj->
id()), info, min, max);
462 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
467 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
473 void MultiObjectPropertyModel::setRange(
const PropertyInfo& info, QWidget* widget)
const
479 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
480 isDoubleType |= OVMPropertyModel<HexahedralMesh>::isDoubleType(info.typeinfo());
485 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
486 isIntType |= OVMPropertyModel<HexahedralMesh>::isIntType(info.typeinfo());
491 double min = +DBL_MAX;
492 double max = -DBL_MAX;
496 range1<double>(*o_it, info, min, max);
499 DoubleWidget* w =
static_cast<DoubleWidget*
>(widget);
500 w->doubleFixedRange->toggle();
501 w->doubleFixedRangeMin->setValue(min);
502 w->doubleFixedRangeMax->setValue(max);
512 range1<int>(*o_it, info, min, max);
515 IntegerWidget* w =
static_cast<IntegerWidget*
>(widget);
516 w->intFixedRange->toggle();
517 w->intFixedRangeMin->setValue(min);
518 w->intFixedRangeMax->setValue(max);
virtual void hideWidget()
Hides the widget.
virtual void duplicateProperty(QModelIndexList selectedIndices)
Duplicates the selected properties.
virtual void connectLogs(PropertyVisualizer *propViz)
Connects the PropertyVisualizer log signals with the log slot.
This class vizualizes a property.
virtual void removeProperty(QModelIndexList selectedIndices)=0
Removes the selected properties.
PropertyT< T > & property(VPropHandleT< T > _ph)
#define DATA_POLYHEDRAL_MESH
Wraps the information of a type.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Handle for a halfedge entity.
virtual void clear(QModelIndexList selectedIndices)
Clears the selected property visualization.
bool dataType(DataType _type) const
virtual void duplicateProperty(QModelIndexList selectedIndices)=0
Duplicates the selected properties.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const =0
Returns the property info for the property with the given index.
virtual void objectUpdated()
Revisualizes visualized properties.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
virtual void gatherProperties()
Searches for properties and creates PropertyVisualizers.
virtual void clear(QModelIndexList selectedIndices)=0
Clears the selected property visualization.
virtual void removeProperty(QModelIndexList selectedIndices)
Removes the selected properties.
virtual void gatherProperties()=0
Searches for properties and creates PropertyVisualizers.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Handle for a vertex entity.
Handle for a edge entity.
virtual void objectUpdated()=0
Revisualizes visualized properties.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const
Returns the property info for the property with the given index.
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList())=0
Visualizes the selected properties.
Handle for a face entity.
bool get_property_handle(VPropHandleT< T > &_ph, const std::string &_name) const
Property classes for the different entity types.
virtual QWidget * getWidget()
Returns the widget.
#define DATA_HEXAHEDRAL_MESH
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList())
Visualizes the selected properties.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
QModelIndex indexFromFancyPropName(const QString &propName) const
Returns the index of the property with the given name.
Cellection of information about a property.
#define DATA_TRIANGLE_MESH
HexahedralMesh * hexahedralMesh(BaseObjectData *_object)
Get an HexahedralMesh from an object.
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.