Commit f4e4f116 authored by Jan Möbius's avatar Jan Möbius

Handle restores in texture control

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9549 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5df146ef
......@@ -561,17 +561,33 @@ void TextureControlPlugin::slotGetCurrentTexture( int _id, QString& _textureName
// Get Texture data for current object
// ================================================================================
TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
if (texData == 0)
if (texData == 0) {
#ifndef NDEBUG
std::cerr << "slotGetCurrentTexture: No Texture Data! "<< obj->getPerObjectDataMap().size() << std::endl;
// Iterate over all per Object datas and output them
QMap<QString, PerObjectData*>::const_iterator mapIter = obj->getPerObjectDataMap().begin();
while ( mapIter != obj->getPerObjectDataMap().end() ) {
std::cerr << "Available Texture Data: " << mapIter.key().toStdString() << std::endl;
mapIter++;
}
#endif
return;
}
// Iterate over all available textures
for ( uint i = 0 ; i < texData->textures().size() ; ++i)
for ( uint i = 0 ; i < texData->textures().size() ; ++i) {
if ( (texData->textures()[i]).enabled() ){
_textureName = (texData->textures()[i]).name();
if ( (texData->textures()[i]).type() == MULTITEXTURE )
if ( (texData->textures()[i]).type() == MULTITEXTURE ) {
return;
}
}
}
}
void TextureControlPlugin::slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures ){
......@@ -1257,7 +1273,6 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
if (texData == 0) {
emit log(LOGERR, tr("doSwitchTexture: Object has no texture data! Object: %1").arg(_id) );
std::cerr << "Object name : " << obj->name().toStdString() << std::endl;
return;
}
......@@ -1613,5 +1628,54 @@ void TextureControlPlugin::getCoordinates1D(QString _textureName, int _id, std::
}
}
void TextureControlPlugin::slotAboutToRestore( int _objectid, int _internalId) {
// ================================================================================
// Get current object
// ================================================================================
BaseObjectData* obj;
if (! PluginFunctions::getObject( _objectid , obj ) ) {
emit log(LOGERR,"slotAboutToRestore: Unable to get Object for id " + QString::number(_objectid) );
}
// ================================================================================
// Get Texture data for current object
// ================================================================================
TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
if (texData == 0) {
// Nothing to do
return;
}
// ================================================================================
// Disable the Texture mapping in the current objects Meshnode
// This will prevent the renderer to crash if the map is wrong after the restore
// ================================================================================
if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
PluginFunctions::triMeshObject(obj)->meshNode()->setTextureMap(0);
} else if ( obj->dataType( DATA_POLY_MESH ) ) {
PluginFunctions::polyMeshObject(obj)->meshNode()->setTextureMap(0);
}
}
void TextureControlPlugin::slotRestore( int _objectid, int _internalId) {
// ================================================================================
// Get the last active texture in the restored perObjectData
// ================================================================================
QString currentTexture;
slotGetCurrentTexture(_objectid,currentTexture);
// ================================================================================
// Enable the last active texture
// ================================================================================
slotSwitchTexture(currentTexture,_objectid);
}
void TextureControlPlugin::slotRestored( int _objectid, int _internalId) {
// Nothing to do yet
}
Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin );
......@@ -52,6 +52,7 @@
#include <QMenuBar>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/TextureInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
......@@ -65,7 +66,7 @@
#include "TextureData.hh"
class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
class TextureControlPlugin : public QObject, BaseInterface, BackupInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
......@@ -74,6 +75,7 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(ContextMenuInterface)
Q_INTERFACES(BackupInterface)
public:
......@@ -125,6 +127,11 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
// LoadSaveInterface
void fileOpened( int _id );
void addedEmptyObject( int _id );
//BackupInterface
void slotAboutToRestore( int _objectid , int _internalId);
void slotRestore( int _objectid, int _internalId);
void slotRestored( int _objectid, int _internalId);
private slots:
......@@ -275,7 +282,7 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
QMenu* contextMenu_;
/** @} */
public slots:
QString version() { return QString("1.0"); };
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment