From 3d11893ec56afb83ca7fafe339a6c428ae8d1d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Wed, 29 Apr 2015 13:19:59 +0000 Subject: [PATCH] Second fix version, now handling deleted objects separatly. Problem was that the object gets deleted after the function got called. closes #2443 git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20608 383ad7c9-94d9-4d36-a494-682f7c89f535 --- MeshObjectInfoPlugin.cc | 108 ++++++++++++++++++++++++---------------- MeshObjectInfoPlugin.hh | 11 +++- 2 files changed, 75 insertions(+), 44 deletions(-) diff --git a/MeshObjectInfoPlugin.cc b/MeshObjectInfoPlugin.cc index 7b6836d..ebd7cb3 100644 --- a/MeshObjectInfoPlugin.cc +++ b/MeshObjectInfoPlugin.cc @@ -823,74 +823,98 @@ bool InfoMeshObjectPlugin::getEdgeLengths(int _id, double &min, double &max, dou //------------------------------------------------------------------------------ -void InfoMeshObjectPlugin::slotObjectUpdated( int _identifier , const UpdateType& _type){ +void InfoMeshObjectPlugin::updateData( int _identifier , const UpdateType& _type, const bool _deleted){ if ( !infoBar_ ) { - return; - } + return; + } - // We only show the information in the status bar if one target mesh is selected. - if ( PluginFunctions::targetCount() == 1 ) { + BaseObjectData* object; + PluginFunctions::getObject(_identifier,object); - BaseObjectData* object; - PluginFunctions::getObject(_identifier,object); + // We only show the information in the status bar if one target mesh is selected or + // If 2 targets where selected, where one is deleted which was target + if ( PluginFunctions::targetCount() == 1 || ( _deleted && (PluginFunctions::targetCount() == 2) && object && object->target() ) ) { - // The object that caused the update is not a target anymore. - // Therefore we need to get the remaining target by iteration. - if ( object && !object->target() ) { - for ( PluginFunctions::ObjectIterator o_it = PluginFunctions::ObjectIterator(PluginFunctions::TARGET_OBJECTS); o_it != PluginFunctions::objectsEnd(); ++o_it ) { - object = *o_it; - } - } + // The object that caused the update is not a target anymore. + // Therefore we need to get the remaining target by iteration. + // If something was deleted, we might see this object here, so make sure, to not take the one with the same id as the deleted one + if ( object && !object->target() ) { + for ( PluginFunctions::ObjectIterator o_it = PluginFunctions::ObjectIterator(PluginFunctions::TARGET_OBJECTS); o_it != PluginFunctions::objectsEnd(); ++o_it ) { + if ( !_deleted || ( o_it->id() != _identifier ) ) { + object = *o_it; + break; + } + } + } - // We only need to update something, if the updated object is the target object - if (object && object->target() ) { + // We only need to update something, if the updated object is the target object + if (object && object->target() ) { - if (object->dataType(DATA_TRIANGLE_MESH)){ + if (object->dataType(DATA_TRIANGLE_MESH)){ - TriMesh* mesh = PluginFunctions::triMesh(object); + TriMesh* mesh = PluginFunctions::triMesh(object); - infoBar_->vertices->setText( QLocale::system().toString( qulonglong(mesh->n_vertices()) ) ); - infoBar_->edges->setText( QLocale::system().toString( qulonglong(mesh->n_edges()) ) ); - infoBar_->faces->setText( QLocale::system().toString( qulonglong(mesh->n_faces()) ) ); + infoBar_->vertices->setText( QLocale::system().toString( qulonglong(mesh->n_vertices()) ) ); + infoBar_->edges->setText( QLocale::system().toString( qulonglong(mesh->n_edges()) ) ); + infoBar_->faces->setText( QLocale::system().toString( qulonglong(mesh->n_faces()) ) ); - infoBar_->showCounts(); + infoBar_->showCounts(); - return; - } + return; + } - if (object->dataType(DATA_POLY_MESH)){ + if (object->dataType(DATA_POLY_MESH)){ - PolyMesh* mesh = PluginFunctions::polyMesh(object); + PolyMesh* mesh = PluginFunctions::polyMesh(object); - infoBar_->vertices->setText( QLocale::system().toString( qulonglong(mesh->n_vertices()) ) ); - infoBar_->edges->setText( QLocale::system().toString( qulonglong(mesh->n_edges()) ) ); - infoBar_->faces->setText( QLocale::system().toString( qulonglong(mesh->n_faces()) ) ); + infoBar_->vertices->setText( QLocale::system().toString( qulonglong(mesh->n_vertices()) ) ); + infoBar_->edges->setText( QLocale::system().toString( qulonglong(mesh->n_edges()) ) ); + infoBar_->faces->setText( QLocale::system().toString( qulonglong(mesh->n_faces()) ) ); - infoBar_->showCounts(); - return; - } + infoBar_->showCounts(); + return; + } - } + } - //infoBar_->hideCounts(); + infoBar_->hideCounts(); - } else { - // Display only count information - if ( PluginFunctions::targetCount() > 1 ) { - infoBar_->showTargetCount( PluginFunctions::targetCount() ); - } else - infoBar_->hideCounts(); - } + } else { + // Display only count information + if ( (PluginFunctions::targetCount() > 1) && object ) { + if ( _deleted && object->target() ) { + infoBar_->showTargetCount( PluginFunctions::targetCount() - 1); + } else { + infoBar_->showTargetCount( PluginFunctions::targetCount() ); + } + } else + infoBar_->hideCounts(); + } + +} + +//------------------------------------------------------------------------------ + +void InfoMeshObjectPlugin::slotObjectUpdated( int _identifier , const UpdateType& _type){ + + updateData(_identifier,_type,false); } //------------------------------------------------------------------------------ void InfoMeshObjectPlugin::slotObjectSelectionChanged( int _identifier ){ - slotObjectUpdated( _identifier , UPDATE_ALL ); + updateData(_identifier,UPDATE_ALL,false); +} + +//------------------------------------------------------------------------------ + +void InfoMeshObjectPlugin::objectDeleted( int _identifier ){ + updateData(_identifier,UPDATE_ALL,true); } + //------------------------------------------------------------------------------ void InfoMeshObjectPlugin::slotAllCleared(){ diff --git a/MeshObjectInfoPlugin.hh b/MeshObjectInfoPlugin.hh index 988461b..58a0603 100644 --- a/MeshObjectInfoPlugin.hh +++ b/MeshObjectInfoPlugin.hh @@ -56,7 +56,7 @@ #include #include - +#include #include #include #include @@ -73,13 +73,14 @@ Plugin to visualize information about objects in the scene */ -class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface, LoggingInterface, StatusbarInterface +class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface, LoggingInterface, StatusbarInterface, LoadSaveInterface { Q_OBJECT Q_INTERFACES(BaseInterface) Q_INTERFACES(InformationInterface) Q_INTERFACES(LoggingInterface) Q_INTERFACES(StatusbarInterface) + Q_INTERFACES(LoadSaveInterface) #if QT_VERSION >= 0x050000 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-MeshObjectInfo") @@ -106,6 +107,9 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface void slotObjectSelectionChanged( int _identifier ); void slotAllCleared(); + // LoadSaveInterface + void objectDeleted( int _identifier ); + void noguiSupported( ) {} ; // InformationInterface @@ -134,6 +138,9 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface template< class MeshT > void printMeshInfo( MeshT* _mesh, int _id, unsigned int _face, ACG::Vec3d& _hitPoint ); + /// Slot that updates the visualization + void updateData( int _identifier , const UpdateType& _type, const bool deleted); + //=========================================================================== /** @name Scripting Functions * @{ */ -- 2.22.2