50 #define OM_PROPERTY_MODEL_CC 52 #include "OMPropertyModel.hh" 54 #include "OMPropertyVisualizerBoolean.hh" 55 #include "OMPropertyVisualizerDouble.hh" 56 #include "OMPropertyVisualizerInteger.hh" 57 #include "OMPropertyVisualizerVector.hh" 58 #include "OMPropertyVisualizerVector2.hh" 59 #include "OMPropertyVisualizerVectorFieldDifference.hh" 61 #ifdef ENABLE_SKELETON_SUPPORT 62 #include "OMPropertyVisualizerSkinWeights.hh" 65 #include "../Utils.hh" 69 #define PROP_VIS "PropertyVisualization" 71 template<
typename MeshT>
81 bCombine.setText(tr(
"Combine"));
83 connect(&bCombine, SIGNAL(clicked()),
84 this, SLOT(slotCombine()));
85 widgets->layout()->addWidget(&bCombine);
86 widgets->layout()->addWidget(&mLoadSaveWidget);
88 connect(mLoadSaveWidget.save_property , SIGNAL(clicked()),
89 this, SLOT(slotSaveProperty()));
91 connect(mLoadSaveWidget.load_property , SIGNAL(clicked()),
92 this, SLOT(slotLoadProperty()));
94 widgets->layout()->addWidget(&mPickWidget);
95 connect(mPickWidget.pickButton, SIGNAL(clicked()),
96 this, SLOT(slotPickProperty()));
98 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
99 mPickWidget.pickButton->setIcon( QIcon(iconPath +
"color-picker.png") );
105 initializeSupportedPropertyTypes();
109 template<
typename MeshT>
114 if (selectedIndices.size() == 2)
116 if (
combinable(propertyVisualizers[selectedIndices[0].row()], propertyVisualizers[selectedIndices[1].row()]))
120 mCombineProperty1 = &propertyVisualizers[selectedIndices[0].row()]->getPropertyInfo();
121 mCombineProperty2 = &propertyVisualizers[selectedIndices[1].row()]->getPropertyInfo();
129 if (selectedIndices.size() == 1)
135 if (mPickWidget.pickButton->isChecked())
140 template<
typename MeshT>
144 filter = tr(
"Vertex Property (*.vprop)");
145 filter += tr(
";; HalfEdge Property (*.hprop)");
146 filter += tr(
";; Edge Property (*.eprop)");
147 filter += tr(
";; Face Property (*.fprop)");
148 filter += tr(
";; All Files (*)");
152 template<
typename MeshT>
160 filter = tr(
"Vertex Property (*.vprop)");
162 filter = tr(
"HalfEdge Property (*.hprop)");
164 filter = tr(
"Edge Property (*.eprop)");
166 filter = tr(
"Face Property (*.fprop)");
168 filter += tr(
";; All Files (*)");
181 template<
typename MeshT>
185 if (isVectorType(mCombineProperty1->typeinfo()))
203 template<
typename MeshT>
211 return (isVectorType(typeInfo1) && isVectorType(typeInfo2)) && (propInfo1.entityType() == propInfo2.entityType());
214 template<
typename MeshT>
217 for (QModelIndexList::const_iterator it = currentlySelectedIndices.begin(), it_end = currentlySelectedIndices.end();
218 it != it_end; ++it) {
223 template<
typename MeshT>
226 QStringList headerParts = header.split(tr(
", "), QString::SkipEmptyParts );
227 int headerVersion = headerParts[0].toUInt();
228 if (headerVersion == 1)
230 n = headerParts[1].toUInt();
231 unsigned int nExpected = 0;
233 PropertyInfo::ENTITY_FILTER filter = (PropertyInfo::ENTITY_FILTER)headerParts[2].toInt();
236 case PropertyInfo::EF_FACE:
237 nExpected = mesh_->n_faces();
239 case PropertyInfo::EF_EDGE:
240 nExpected = mesh_->n_edges();
242 case PropertyInfo::EF_HALFEDGE:
243 nExpected = mesh_->n_halfedges();
245 case PropertyInfo::EF_VERTEX:
246 nExpected = mesh_->n_vertices();
255 emit log(
LOGERR,
"Could not load property: unexpected number of entities");
259 QString friendlyName = headerParts[3];
263 emit log(
LOGERR, tr(
"Could not load property: unsupported property type %1").arg(friendlyName));
269 QString propName = QInputDialog::getText(0,
"Property Name",
"Please enter name.",
QLineEdit::Normal,headerParts[4]);
270 if (propName ==
"")
return false;
272 bool replace =
false;
279 propName = QInputDialog::getText(0,
"New Property Name",
"Please enter new name.");
280 else if (msgBox->cancel)
282 else if (msgBox->replace)
301 emit log(
LOGERR,
"Could not load property: unsupported header format");
307 template<
typename MeshT>
310 #ifdef ENABLE_SKELETON_SUPPORT 313 for (
unsigned int i = 0; i < n; ++i)
315 QString propertyText =
"";
317 while ((tmp =
readLine(file_stream_)) !=
"")
318 propertyText = propertyText + tmp;
329 template<
typename MeshT>
342 template<
typename MeshT>
345 if ( mPickWidget.pickButton->isChecked() ){
359 template<
typename MeshT>
362 pickModeActive = (_mode == PROP_VIS);
366 lastPickMode = _mode;
369 mPickWidget.pickButton->setChecked(pickModeActive);
378 template<
typename MeshT>
381 if (!pickModeActive)
return;
383 if (_event->type() == QEvent::MouseButtonPress)
385 unsigned int node_idx, face_idx;
392 if (object->
id() == objectID_)
396 mPickWidget.pickedHandle->setText(tr(
"%1").arg(primitiveId));
403 template<
typename MeshT>
406 return (typeInfo == proptype_Vec3f) || (typeInfo == proptype_Vec3d);
409 template<
typename MeshT>
411 typename MeshT::prop_iterator props_first,
412 typename MeshT::prop_iterator props_last,
413 PropertyInfo::ENTITY_FILTER filter)
415 for (
typename MeshT::prop_iterator pit = props_first; pit != props_last; ++pit) {
422 template<
typename MeshT>
427 gatherProperties(mesh_, mesh_->fprops_begin(), mesh_->fprops_end(), PropertyInfo::EF_FACE);
428 gatherProperties(mesh_, mesh_->eprops_begin(), mesh_->eprops_end(), PropertyInfo::EF_EDGE);
429 gatherProperties(mesh_, mesh_->hprops_begin(), mesh_->hprops_end(), PropertyInfo::EF_HALFEDGE);
430 gatherProperties(mesh_, mesh_->vprops_begin(), mesh_->vprops_end(), PropertyInfo::EF_VERTEX);
443 template<
typename MeshT>
447 TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
448 return propIt != supportedPropertyTypes.end();
461 template<
typename MeshT>
464 for (TypeInfoWrapperSet::const_iterator it = supportedPropertyTypes.begin();
465 it != supportedPropertyTypes.end();
468 if (friendlyName.toStdString().compare(it->getName()) == 0)
482 template<
typename MeshT>
485 for (
unsigned int i = 0; i < propertyVisualizers.size(); ++i)
487 const PropertyInfo& propInfo = propertyVisualizers[i]->getPropertyInfo();
501 template<
typename MeshT>
505 TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
516 template<
typename MeshT>
519 for (TypeInfoWrapperSet::const_iterator it = supportedPropertyTypes.begin();
520 it != supportedPropertyTypes.end();
523 if (friendlyName.toStdString().compare(it->getName()) == 0)
526 throw std::exception();
540 template<
typename MeshT>
544 if (propInfo.typeinfo() == proptype_bool)
546 else if (propInfo.typeinfo() == proptype_int)
548 else if (propInfo.typeinfo() == proptype_uint)
550 else if (propInfo.typeinfo() == proptype_uint8_t)
552 else if (propInfo.typeinfo() == proptype_double)
554 else if ((propInfo.typeinfo() == proptype_Vec3d) || (propInfo.typeinfo() == proptype_Vec3f))
556 else if ((propInfo.typeinfo() == proptype_Vec2d))
558 else if ((propInfo.typeinfo() == proptype_Vec2f))
560 #ifdef ENABLE_SKELETON_SUPPORT 561 else if (propInfo.typeinfo() == proptype_SkinWeights)
562 propertyVisualizers.push_back(
new OMPropertyVisualizerSkinWeights<MeshT>(mesh, propInfo));
577 template<
typename MeshT>
581 QString dtype = friendlyTypeName;
582 QString pname = propName;
586 if ( filter == PropertyInfo::EF_VERTEX )
588 if ( (dtype == tr(
"Vec3d")) || (dtype == tr(
"Vec3f")) )
591 mesh->add_property(prop, pname.toStdString());
593 else if (dtype == tr(
"Vec2d"))
596 mesh->add_property(prop, pname.toStdString());
598 else if (dtype == tr(
"Vec2f"))
601 mesh->add_property(prop, pname.toStdString());
603 else if ( dtype == tr(
"double") )
606 mesh->add_property(prop, pname.toStdString());
608 else if ( dtype == tr(
"unsigned int") )
611 mesh->add_property(prop, pname.toStdString());
613 else if ( dtype == tr(
"uint8_t") )
616 mesh->add_property(prop, pname.toStdString());
618 else if ( dtype == tr(
"int") )
621 mesh->add_property(prop, pname.toStdString());
623 else if ( dtype == tr(
"bool") )
626 mesh->add_property(prop, pname.toStdString());
630 #ifdef ENABLE_SKELETON_SUPPORT 631 else if ( dtype == tr(
"SkinWeights") )
634 mesh->add_property(prop, pname.toStdString());
638 else if ( filter == PropertyInfo::EF_EDGE )
640 if ( (dtype == tr(
"Vec3d")) || (dtype == tr(
"Vec3f")) )
643 mesh->add_property(prop, pname.toStdString());
645 else if ( dtype == tr(
"Vec2d") )
648 mesh->add_property(prop, pname.toStdString());
650 else if ( dtype == tr(
"Vec2f") )
653 mesh->add_property(prop, pname.toStdString());
655 else if ( dtype == tr(
"double") )
658 mesh->add_property(prop, pname.toStdString());
660 else if ( dtype == tr(
"unsgined int") )
663 mesh->add_property(prop, pname.toStdString());
665 else if ( dtype == tr(
"uint8_t") )
668 mesh->add_property(prop, pname.toStdString());
670 else if ( dtype == tr(
"int") )
673 mesh->add_property(prop, pname.toStdString());
675 else if ( dtype == tr(
"bool") )
678 mesh->add_property(prop, pname.toStdString());
681 else if ( filter == PropertyInfo::EF_FACE )
683 if ( (dtype == tr(
"Vec3d")) || (dtype == tr(
"Vec3f")) )
686 mesh->add_property(prop, pname.toStdString());
688 else if ( dtype == tr(
"Vec2d") )
691 mesh->add_property(prop, pname.toStdString());
693 else if ( dtype == tr(
"Vec2f") )
696 mesh->add_property(prop, pname.toStdString());
698 else if ( dtype == tr(
"double") )
701 mesh->add_property(prop, pname.toStdString());
703 else if ( dtype == tr(
"unsigned int") )
706 mesh->add_property(prop, pname.toStdString());
708 else if ( dtype == tr(
"uint8_t") )
711 mesh->add_property(prop, pname.toStdString());
713 else if ( dtype == tr(
"int") )
716 mesh->add_property(prop, pname.toStdString());
718 else if ( dtype == tr(
"bool") )
721 mesh->add_property(prop, pname.toStdString());
724 else if ( filter == PropertyInfo::EF_HALFEDGE )
726 if ( (dtype == tr(
"Vec3d")) || (dtype == tr(
"Vec3f")) )
729 mesh->add_property(prop, pname.toStdString());
731 else if ( dtype == tr(
"double") )
734 mesh->add_property(prop, pname.toStdString());
736 else if ( dtype == tr(
"unsigned int") )
739 mesh->add_property(prop, pname.toStdString());
741 else if ( dtype == tr(
"uint8_t") )
744 mesh->add_property(prop, pname.toStdString());
746 else if ( dtype == tr(
"int") )
749 mesh->add_property(prop, pname.toStdString());
751 else if ( dtype == tr(
"bool") )
754 mesh->add_property(prop, pname.toStdString());
761 template<
typename MeshT>
766 supportedPropertyTypes.insert(proptype_bool);
767 supportedPropertyTypes.insert(proptype_int);
768 supportedPropertyTypes.insert(proptype_uint);
769 supportedPropertyTypes.insert(proptype_uint8_t);
770 supportedPropertyTypes.insert(proptype_double);
771 supportedPropertyTypes.insert(proptype_Vec3d);
772 supportedPropertyTypes.insert(proptype_Vec3f);
773 supportedPropertyTypes.insert(proptype_Vec2d);
774 supportedPropertyTypes.insert(proptype_Vec2f);
776 #ifdef ENABLE_SKELETON_SUPPORT 777 supportedPropertyTypes.insert(proptype_SkinWeights);
bool combinable(PropertyVisualizer *propertyVisualizer1, PropertyVisualizer *propertyVisualizer2)
Checks if two properties are combinable.
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
virtual void setPropertyFromFile(QTextStream *&file_stream_, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
Asks the user how to proceed after a name clash.
Add normals to mesh item (vertices/faces)
void addPropertyVisualizer(OpenMesh::BaseProperty *const baseProp, MeshT *mesh, PropertyInfo::ENTITY_FILTER filter)
Adds a new PropertyVisualizer.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
virtual void setPropertyFromText(unsigned int index, QString text)=0
Returns the value of a property in text form.
Cellection of information about a property.
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
This class vizualizes a property.
virtual void pickProperty()
Toggle picking on and off.
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
virtual void mouseEvent(QMouseEvent *_event)
Handles mouse events for picking.
const std::string pickMode()
Get the current Picking mode.
void gatherProperties()
Searches for all properties and creates the visualizers.
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
virtual void setPropertyFromFile(QTextStream *&file_stream_, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if the property name is still available.
bool isSupported(OpenMesh::BaseProperty *const baseProp) const
Checks if visualizing this property is supported.
virtual void pickModeChanged(const std::string &_mode)
Handles changing of pick mode.
const std::string & name() const
Return the name of the property.
void connectLogs(PropertyVisualizer *propViz)
Connects the PropertyVisualizer log signals with the log slot.
Viewer::ActionMode actionMode()
Get the current Action mode.
virtual void combine()
Combines two properties.
TypeInfoWrapper getSupportedTypeInfoWrapper(OpenMesh::BaseProperty *const baseProp)
Returns the TypeInfoWrapper for the property if it is supported.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
virtual void saveProperty()
Saves the currently slected properties.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
void resetPicking()
Disables picking.
void addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
Adds a new property to the mesh.
QString readLine(QTextStream *file_stream_)
Read line from a file.
void saveProperty(unsigned int propId)
Saves property.
Added for signal/slot support.
Wraps the information of a type.
bool isNew(OpenMesh::BaseProperty *const baseProp, PropertyInfo::ENTITY_FILTER filter)
Checks if we already created a PropertyVisualizer for this property.
unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint)
Returns the ID of the closest primitive.
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
picks faces (should be implemented for all nodes)