TextureControl.cc 81.6 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33 34 35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
42 43


Matthias Möller's avatar
Matthias Möller committed
44 45 46 47 48
#if QT_VERSION >= 0x050000 
  #include <QtWidgets>
#else
  #include <QtGui>
#endif
49 50 51 52 53


#include "TextureControl.hh"

#include <iostream>
54
#include <ACG/GL/GLState.hh>
55 56

#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
Jan Möbius's avatar
Jan Möbius committed
57
#include "OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh"
58
#include "OpenFlipper/common/GlobalOptions.hh"
59
#include "ImageStorage.hh"
60

61 62 63 64
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
#include "ObjectTypes/VolumeMeshObject/VolumeMeshDrawModesContainer.hh"
#endif

65
#define TEXTUREDATA "TextureData"
66
 
67

Jan Möbius's avatar
Jan Möbius committed
68 69 70 71 72 73 74 75 76 77

TextureControlPlugin::TextureControlPlugin() :
settingsDialog_(0),
textureMenu_(0),
actionGroup_(0),
contextMenu_(0)
{

}

Dirk Wilden's avatar
Dirk Wilden committed
78 79 80 81 82
void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , uint _dimension , int _id)
{
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
83
    emit log(LOGERR,"slotTextureAdded: Unable to get Object for id " + QString::number(_id) );
84
    return;
Dirk Wilden's avatar
Dirk Wilden committed
85 86 87 88 89 90 91 92 93
  }

  // Get Texture data for this object or create one if it does not exist
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
    texData = new TextureData();
    obj->setObjectData(TEXTUREDATA, texData);
  }

94
  if ( texData->textureExists(_textureName) ) {
95
    emit log(LOGERR,"slotTextureAdded: Trying to add already existing texture " + _textureName + " for object " + QString::number(_id) );
Dirk Wilden's avatar
Dirk Wilden committed
96 97
    return;
  }
98 99 100 101 102

  // ================================================================================
  // Get the image file
  // ================================================================================

103 104
  // Add Image to the image store and set the index in the texture description
  int newId = imageStore().addImageFile(_filename);
105

106 107 108 109
  if ( newId == -1 ) {
    emit log(LOGERR,imageStore().error());
    return;
  }
110 111 112 113 114 115 116 117

  // ================================================================================
  // Add the texture to the texture node and get the corresponding id
  // ================================================================================
  GLuint glName = 0;

  //inform textureNode about the new texture
  if( obj->dataType( DATA_TRIANGLE_MESH ) )
118
    glName = PluginFunctions::triMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newId,0));
119 120

  if ( obj->dataType( DATA_POLY_MESH ) )
121
    glName = PluginFunctions::polyMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newId,0));
122

123 124 125 126 127 128 129 130 131
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  if ( obj->dataType( DATA_HEXAHEDRAL_MESH ) )
    glName = PluginFunctions::hexahedralMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newId,0));
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  if ( obj->dataType( DATA_POLYHEDRAL_MESH ) )
    glName = PluginFunctions::polyhedralMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newId,0));
#endif

132 133 134 135 136
  // ================================================================================
  // Store texture information in objects metadata
  // ================================================================================

  if (glName == 0) {
137
    emit log(LOGERR,"slotTextureAdded: Unable to bind texture!");
138 139 140 141
    return;
  }

  texData->addTexture(_textureName,_filename,_dimension,glName);
142 143 144 145

  // Remember id in texture descriptor
  texData->setImage(_textureName,newId);

146
  texData->texture(_textureName).disable();
Dirk Wilden's avatar
Dirk Wilden committed
147 148
}

149 150
void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , uint _dimension)
{
151 152 153
  // Add this texture to the list of global textures
  if ( ! globalTextures_.textureExists(_textureName) ) {
    globalTextures_.addTexture(_textureName,_filename,_dimension,0);
154
    globalTextures_.texture(_textureName).disable();
155

156
    int newImageId = imageStore().addImageFile(_filename);
157

158 159 160 161
    if ( newImageId == -1 ) {
      emit log(LOGERR,imageStore().error());
      return;
    }
162

163
    globalTextures_.texture(_textureName).textureImageId(newImageId);
164

165
  } else {
166
    emit log(LOGERR,"slotTextureAdded: Trying to add already existing global texture " + _textureName );
167 168
    return;
  }
169

170
  // Add a new entry to the global Texture menu
171
  QAction* new_texture = new QAction(_textureName, this);
172
  new_texture->setStatusTip(tr("slotTextureAdded: Switch all objects to this Texture ( if available )"));
173 174 175 176 177
  new_texture->setCheckable(true);
  actionGroup_->addAction(new_texture);
  textureMenu_->addAction(new_texture);
  new_texture->setChecked(true);
  textureActions_.push_back(new_texture);
178

179
}
180

181
void TextureControlPlugin::slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId ) {
182 183 184
   // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
185
    emit log(LOGERR,"slotMultiTextureAdded: Unable to get Object for id " + QString::number(_id) );
186 187 188 189
  }

  // Check if we support this kind of data
  if ( !obj->dataType(DATA_TRIANGLE_MESH) && !obj->dataType(DATA_POLY_MESH) ) {
190
      emit log(LOGERR,"slotMultiTextureAdded: Trying to add textures to object failed because of unsupported object type");
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
      return;
  }

  // Get Texture data for this object or create one if it does not exist
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
    texData = new TextureData();
    obj->setObjectData(TEXTUREDATA, texData);
  }

  if ( !texData->textureExists( _textureGroup ) )
    texData->addMultiTexture( _textureGroup );

  // Add the texture
  slotTextureAdded( _name , _filename , 2 , _id);

  // Get the id of the new texture
208
  _textureId = texData->texture(_name).id();
209

210 211 212
  //hide the texture (its accessible through the multiTexture)
  texData->texture(_name).hidden( true );

213
  // Add to image store
214
  int newImageId = imageStore().addImageFile(_filename);
215

216 217 218 219
  if ( newImageId == -1 ) {
    emit log(LOGERR,imageStore().error());
    return;
  }
220

221 222
  // Add to texture description
  texData->texture(_name).textureImageId(newImageId);
223 224 225 226 227

  // Store the new texture in the list of this textureGroup
  if ( _textureId != -1 ) {
    texData->texture(_textureGroup).multiTextureList << _name ;
  } else {
228
    emit log(LOGERR,"slotMultiTextureAdded: Error when getting internal id of new multitexture!");
229 230 231 232 233
  }

}

void TextureControlPlugin::addedEmptyObject( int _id ) {
234

235 236 237
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
238
//     emit log(LOGERR,"addedEmptyObject: Unable to get Object for id " + QString::number(_id) );
239 240 241 242
    return;
  }
  
  // Check if we support this kind of data
243 244 245 246 247 248 249 250 251
  if ( !obj->dataType(DATA_TRIANGLE_MESH)   && !obj->dataType(DATA_POLY_MESH)
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
       && !obj->dataType(DATA_HEXAHEDRAL_MESH)
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
       && !obj->dataType(DATA_POLYHEDRAL_MESH)
#endif
     )
  {
252 253 254 255 256 257 258 259 260 261 262 263
    return;
  }
  
  // Get Texture data for this object or create one if it does not exist
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
    texData = new TextureData();
    obj->setObjectData(TEXTUREDATA, texData);
  }
  
  // Iterate over all available global textures and add them to the object
  for ( uint i = 0 ; i < globalTextures_.textures().size() ; ++i) {
264 265 266 267 268 269 270 271 272

    // Add to image store
    int newImageId = imageStore().addImageFile(globalTextures_.textures()[i].filename());

    if ( newImageId == -1 ) {
      emit log(LOGERR,imageStore().error());
      continue;
    }

273 274 275 276 277 278 279
    // ================================================================================
    // Add the texture to the texture node and get the corresponding id
    // ================================================================================
    GLuint glName = 0;
    
    //inform textureNode about the new texture
    if( obj->dataType( DATA_TRIANGLE_MESH ) )
280
      glName = PluginFunctions::triMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newImageId,0));
281

282
    if ( obj->dataType( DATA_POLY_MESH ) )
283
      glName = PluginFunctions::polyMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newImageId,0));
284 285 286 287 288 289 290 291 292

#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
    if( obj->dataType( DATA_HEXAHEDRAL_MESH ) )
      glName = PluginFunctions::hexahedralMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newImageId,0));
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
    if ( obj->dataType( DATA_POLYHEDRAL_MESH ) )
      glName = PluginFunctions::polyhedralMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newImageId,0));
#endif
293 294 295 296 297 298
    
    // ================================================================================
    // Store texture information in objects metadata
    // ================================================================================
    if (glName != 0) {
      texData->addTexture(globalTextures_.textures()[i], glName);
299 300 301

      // Add to texture description
      texData->setImage(globalTextures_.textures()[i].name(),newImageId);
302 303
    }
    else {
304
      imageStore().removeImage(newImageId);
305
      emit log(LOGERR,"addedEmptyObject: Unable to bind Texture");
306 307 308 309 310 311 312 313 314 315
      continue;
    }
    
    
    // ================================================================================
    // Update texture mapping in meshNode
    // ================================================================================
    if( obj->dataType( DATA_TRIANGLE_MESH ) ){
      PluginFunctions::triMeshObject(obj)->meshNode()->setTextureMap( 0 );
    }
316

317 318 319 320 321
    if ( obj->dataType( DATA_POLY_MESH ) ){
      PluginFunctions::polyMeshObject(obj)->meshNode()->setTextureMap( 0 );
    }
    
  }
322 323
}

324
template< typename MeshT >
Jan Möbius's avatar
Jan Möbius committed
325
void TextureControlPlugin::handleFileOpenTextures( MeshT*& _mesh , int _objectId ) {
326

327 328 329 330 331 332
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _objectId , obj ) ) {
    return;
  }

333 334 335 336 337
  if ( _mesh->has_vertex_texcoords2D() ){
    slotTextureAdded("Original Per Vertex Texture Coords","unknown.png",2,_objectId);
    slotSetTextureMode("Original Per Vertex Texture Coords","type=vertexbased",_objectId);
  }

338
  if ( _mesh->has_halfedge_texcoords2D() ){
339 340 341
    slotTextureAdded("Original Per Face Texture Coords","unknown.png",2,_objectId);
    slotSetTextureMode("Original Per Face Texture Coords","type=halfedgebased",_objectId);
  }
342

343 344
}

345 346 347 348 349 350 351 352 353 354 355 356
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
template< typename VolumeMeshObjectT >
void TextureControlPlugin::handleFileOpenTexturesOVM( VolumeMeshObjectT* _obj, int _objectId ) {

  if ( _obj->texcoords().vertex_texcoords_available() ){
    slotTextureAdded("Original Per Vertex Texture Coords","unknown.png",2,_objectId);
    slotSetTextureMode("Original Per Vertex Texture Coords","type=vertexbased",_objectId);
  }

}
#endif

357
void TextureControlPlugin::fileOpened( int _id ) {
358
  // TODO:: Store original texture coords in a new property!
Jan Möbius's avatar
Jan Möbius committed
359

360 361 362
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
363
    emit log(LOGERR,"fileOpened: Unable to get Object for id " + QString::number(_id) );
364
    return;
365 366 367
  }

  // Check if we support this kind of data
368 369 370 371 372 373 374 375 376
  if ( !obj->dataType(DATA_TRIANGLE_MESH) && !obj->dataType(DATA_POLY_MESH)
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
       && !obj->dataType(DATA_HEXAHEDRAL_MESH)
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
       && !obj->dataType(DATA_POLYHEDRAL_MESH)
#endif
     )
  {
377
      return;
378 379
  }

380 381 382
  // Get Texture data for this object or create one if it does not exist
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
383 384
    emit log(LOGERR,tr("fileOpened: Unable to get texture object data for id %1.").arg(_id) );
    return;
385
  }
386 387 388 389 390

  // Check if the file contains a texture map, store original textures and handle them before adding global textures
  if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
    TriMesh* mesh = PluginFunctions::triMesh(obj);
    if ( mesh )
Jan Möbius's avatar
Jan Möbius committed
391
      handleFileOpenTextures(mesh,_id);
392 393 394
  } else if ( obj->dataType( DATA_POLY_MESH ) ) {
    PolyMesh* mesh = PluginFunctions::polyMesh(obj);
    if ( mesh )
Jan Möbius's avatar
Jan Möbius committed
395
      handleFileOpenTextures(mesh,_id);
396
  }
397 398 399 400 401 402 403 404 405 406 407 408
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( obj->dataType( DATA_HEXAHEDRAL_MESH ) ) {
    HexahedralMeshObject* ovm_obj = PluginFunctions::hexahedralMeshObject(_id);
    handleFileOpenTexturesOVM(ovm_obj, _id);
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( obj->dataType( DATA_POLYHEDRAL_MESH ) ) {
    PolyhedralMeshObject* ovm_obj = PluginFunctions::polyhedralMeshObject(_id);
    handleFileOpenTexturesOVM(ovm_obj, _id);
  }
#endif
409

410 411
}

412 413 414 415 416 417 418
void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage& _image , int _id ) {

  // ================================================================================
  // Get the new object
  // ================================================================================
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
419
    emit log(LOGERR,"slotTextureChangeImage: Unable to get Object for id " + QString::number(_id) );
420 421 422 423 424 425 426 427
  }

  // ================================================================================
  // Get Texture data for this object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );

  if ( texData == 0 || ( !texData->textureExists(_textureName))  ) {
428
    emit log(LOGERR,"slotTextureChangeImage: Texture does not exist: " + _textureName + " (objectid=" + QString::number(_id) + ")");
429 430 431 432 433 434 435
    return;
  }

  // ================================================================================
  // Update the image
  // ================================================================================
  Texture& texture = texData->texture(_textureName);
436 437 438 439 440 441

  // Add to image store
  int newImageId = imageStore().addImage(_image);

  // Add to texture description
  texture.textureImageId(newImageId);
442 443 444 445 446

  // ================================================================================
  // Flag dirty or update
  // ================================================================================

447 448 449 450 451
  if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
    PluginFunctions::triMeshObject(obj)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
  } else if ( obj->dataType( DATA_POLY_MESH ) ) {
    PluginFunctions::triMeshObject(obj)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
  }
452 453 454 455 456 457 458 459 460 461
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( obj->dataType( DATA_HEXAHEDRAL_MESH ) ) {
    PluginFunctions::hexahedralMeshObject(obj)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( obj->dataType( DATA_POLYHEDRAL_MESH ) ) {
    PluginFunctions::polyhedralMeshObject(obj)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
  }
#endif
462 463

  emit updateView();
464 465 466 467 468 469 470 471 472

}

void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage& _image ) {

  // ================================================================================
  // Update texture Image for global textures
  // ================================================================================
  if ( ! globalTextures_.textureExists(_textureName) ) {
473
    emit log(LOGERR,"slotTextureChangeImage: Global texture does not exist: " + _textureName);
474 475 476 477 478 479 480
    return;
  }

  // ================================================================================
  // Update the image in the global texture
  // ================================================================================
  Texture& texture = globalTextures_.texture(_textureName);
481 482 483 484 485 486

  // Add to image store
  int newImageId = imageStore().addImage(_image);

  // Add to texture description
  texture.textureImageId(newImageId);
487 488 489 490 491 492 493 494 495 496

  // ================================================================================
  // check if the local textures need to be updated
  // ================================================================================
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it){

    TextureData* texData = dynamic_cast< TextureData* > ( o_it->objectData(TEXTUREDATA) );
    if (texData != 0)
      if ( texData->textureExists(_textureName) ){
        Texture& localTex = texData->texture(_textureName);
497
        localTex.textureImageId(newImageId);
498

499 500 501 502 503
          if( o_it->dataType( DATA_TRIANGLE_MESH ) ) {
            PluginFunctions::triMeshObject(o_it)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
          } else if ( o_it->dataType( DATA_POLY_MESH ) ) {
            PluginFunctions::triMeshObject(o_it)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
          }
504 505 506 507 508 509 510 511 512 513
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
          else if ( o_it->dataType( DATA_HEXAHEDRAL_MESH ) ) {
            PluginFunctions::hexahedralMeshObject(o_it)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
          }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
          else if ( o_it->dataType( DATA_POLYHEDRAL_MESH ) ) {
            PluginFunctions::polyhedralMeshObject(o_it)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
          }
#endif
514 515 516
      }
  }

517 518
  emit updateView();

519 520
}

521
void TextureControlPlugin::slotTextureGetImage( QString _textureName, QImage& _image, int _id ){
522

523 524 525
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
526
    emit log(LOGERR,"slotTextureGetImage: Unable to get Object for id " + QString::number(_id) );
527 528 529 530 531 532 533
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
534
    emit log(LOGERR, tr("slotTextureGetImage: Object has no texture data! Object: %1").arg(_id) );
535 536 537 538 539 540 541
    return;
  }

  // ================================================================================
  // Check for requested Texture
  // ================================================================================
  if ( !texData->textureExists(_textureName) ) {
542
    emit log(LOGERR, "slotTextureGetImage: Texture not available! " + _textureName );
543 544 545 546 547 548
    return;
  }

  if ( texData->texture(_textureName).type() == MULTITEXTURE )
    _image = QImage();
  else
549
    _image = imageStore().getImage(texData->texture(_textureName).textureImageId(),0 );
550 551
}

552

553
void TextureControlPlugin::slotTextureGetImage( QString _textureName, QImage& _image ){
554

555
  if ( ! globalTextures_.textureExists(_textureName) ) {
556
    emit log(LOGERR,"slotTextureGetImage: Global texture does not exist: " + _textureName);
557 558 559 560 561 562
    return;
  }

  if ( globalTextures_.texture(_textureName).type() == MULTITEXTURE )
    _image = QImage();
  else
563
    _image = imageStore().getImage(globalTextures_.texture(_textureName).textureImageId(),0);
564 565
}

566
void TextureControlPlugin::slotTextureIndex( QString _textureName, int _id, int& _index){
567

568 569 570
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
571
    emit log(LOGERR,"slotTextureIndex: Unable to get Object for id " + QString::number(_id) );
572 573 574 575 576 577 578
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
579
    emit log(LOGERR, tr("slotTextureIndex: Object has no texture data! Object: %1").arg(_id) );
580 581 582 583 584 585 586
    return;
  }

  // ================================================================================
  // Check for requested Texture
  // ================================================================================
  if ( !texData->textureExists(_textureName) ) {
587
    emit log(LOGERR, "slotTextureIndex: Texture not available! " + _textureName );
588 589 590 591 592 593
    return;
  }

  _index = texData->texture(_textureName).id();
}

594
void TextureControlPlugin::slotTextureIndexPropertyName(int _id, QString& _propertyName) {
595

596 597 598
    // Get the object
    BaseObjectData* obj;
    if (! PluginFunctions::getObject(  _id , obj ) ) {
599
        emit log(LOGERR,"slotTextureIndexPropertyName: Unable to get Object for id " + QString::number(_id) );
600 601 602 603 604 605
        return;
    }
    
    // Get texture index property name
    if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
        _propertyName = PluginFunctions::triMeshObject(obj)->meshNode()->indexPropertyName().c_str();
606
    } else if( obj->dataType( DATA_POLY_MESH ) ) {
607 608
        _propertyName = PluginFunctions::polyMeshObject(obj)->meshNode()->indexPropertyName().c_str();
    } else {
609
        emit log(LOGERR,"slotTextureIndexPropertyName: Unable to access mesh for object with id " + QString::number(_id) );
610 611 612
    }
}

613
void TextureControlPlugin::slotTextureName( int _id, int _textureIndex, QString& _textureName){
614

615 616 617
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
618
    emit log(LOGERR,"slotTextureName: Unable to get Object for id " + QString::number(_id) );
619 620 621 622 623 624 625
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
626
    emit log(LOGERR, tr("slotTextureName: Object has no texture data! Object: %1").arg(_id) );
627 628 629 630 631 632 633 634 635
    return;
  }

  for (uint i=0; i < texData->textures().size(); i++ )
    if ( (texData->textures()[i]).id() == _textureIndex ){
      _textureName = (texData->textures()[i]).name();
      return;
    }

636
  emit log(LOGERR, "slotTextureName: TextureIndex not available! (" + QString::number(_textureIndex) + ")" );
637 638 639 640
  _textureName = "NOT_FOUND";
  return;
}

641
void TextureControlPlugin::slotTextureFilename( int _id, QString _textureName, QString& _textureFilename){
642

643 644 645
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
646
    emit log(LOGERR,"slotTextureFilename: Unable to get Object for id " + QString::number(_id) );
647 648 649 650 651 652 653
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
654
    emit log(LOGERR, tr("slotTextureFilename: Object has no texture data! Object: %1").arg(_id) );
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
    return;
  }

  // Search in local textures
  for (uint i=0; i < texData->textures().size(); i++ ) {
      for (int j=0; j < texData->textures()[i].multiTextureList.size(); j++ ) {
          if ( (texData->textures()[i]).name() == _textureName ){
              Texture& tex = texData->texture((texData->textures()[i]).name());
              _textureFilename = tex.filename();
              return;
          } else if ( (texData->textures()[i]).multiTextureList[j] == _textureName ){
              Texture& tex = texData->texture((texData->textures()[i]).multiTextureList[j]);
              _textureFilename = tex.filename();
              return;
          }
      }
  }
  
  _textureFilename = OpenFlipper::Options::textureDir().path() + 
674
      QDir::separator().toLatin1() + (globalTextures_.texture(_textureName)).filename();
675 676 677 678 679 680 681
  
  QFile f(_textureFilename);
  if(!f.exists()) _textureFilename = "NOT_FOUND";
  
  return;
}

682
void TextureControlPlugin::slotGetCurrentTexture( int _id, QString& _textureName ){
683

Dirk Wilden's avatar
Dirk Wilden committed
684 685
  _textureName = "NONE";
  
686 687 688
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
689
    emit log(LOGERR,"slotGetCurrentTexture: Unable to get Object for id " + QString::number(_id) );
690 691 692 693 694 695
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
696 697 698 699 700 701
  if (texData == 0) {
    #ifndef NDEBUG
    
      // Iterate over all per Object datas and output them
      QMap<QString, PerObjectData*>::const_iterator mapIter = obj->getPerObjectDataMap().begin();  
      while ( mapIter != obj->getPerObjectDataMap().end() ) {
702
        ++mapIter;
703 704 705
      }
    #endif
    
706
    return;
707
  }
708 709
  
  // Iterate over all available textures
710 711
  for ( uint i = 0 ; i < texData->textures().size() ; ++i) {
  
712 713 714
    if ( (texData->textures()[i]).enabled() ){
      _textureName = (texData->textures()[i]).name();
      
715
      if ( (texData->textures()[i]).type() == MULTITEXTURE ) {
716
        return;
717
      }
718
    }
719
  }
720 721 722 723 724 725
}

void TextureControlPlugin::slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures ){
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
726
    emit log(LOGERR,"slotGetSubTextures: Unable to get Object for id " + QString::number(_id) );
727 728 729 730 731 732 733
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
734
    emit log(LOGERR, tr("slotGetSubTextures: Object has no texture data! Object: %1").arg(_id) );
735 736 737 738 739 740 741
    return;
  }

  // ================================================================================
  // Check for requested Texture
  // ================================================================================
  if ( !texData->textureExists(_multiTextureName) ) {
742
    emit log(LOGERR, "slotGetSubTextures: Texture not available! " + _multiTextureName );
743 744 745 746 747 748 749 750 751 752
    return;
  }
  
  if ( texData->texture(_multiTextureName).type() == MULTITEXTURE )
    _subTextures = texData->texture(_multiTextureName).multiTextureList;
  else
    _subTextures = QStringList();
}

void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _identifier ){
753

754 755 756 757 758
  // ================================================================================
  // Get updated object
  // ================================================================================
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _identifier , obj ) ) {
759
    emit log(LOGERR,"slotTextureUpdated: Unable to get Object for id " + QString::number(_identifier) );
760 761
    return;
  }
762

763
  //skip object if its not a mesh
764 765 766 767 768 769 770 771
  if(   !obj->dataType( DATA_TRIANGLE_MESH )   && !obj->dataType( DATA_POLY_MESH )
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
     && !obj->dataType( DATA_HEXAHEDRAL_MESH )
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
     && !obj->dataType( DATA_POLYHEDRAL_MESH )
#endif
    )
772 773
    return;

774 775 776 777 778
  // ================================================================================
  // Get objects texture data and verify that texture exists
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
779
    emit log(LOGERR,tr("slotTextureUpdated: Texture data not found: Object %1" ).arg(_identifier) );
780
    return;
781
  }
782

783 784 785
  // ================================================================================
  // Check if texture exists
  // ================================================================================
786
  if ( ! texData->textureExists(_textureName) ) {
787
    emit log(LOGERR,"slotTextureUpdated: Texture " + _textureName + " not found on object " + QString::number(_identifier) );
788
    return;
789
  }
790

791 792 793
  // ================================================================================
  // If texture is not enabled, mark it as dirty and defer update to visualization update
  // ================================================================================
794
  if ( ! texData->texture(_textureName).enabled() ) {
795
    texData->texture(_textureName).setDirty();
796 797
    return;
  }
798

799
  // ================================================================================
800
  // Enable the texture in texture node
801 802 803 804
  // ================================================================================
  if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
    TriMesh* mesh = PluginFunctions::triMesh(obj);
    doUpdateTexture(texData->texture(_textureName), *mesh);
805 806 807
    // Texture has been bound to that object by slotAddTexture.. directly or by fileOpened from global texture
    // Just activate it
    PluginFunctions::triMeshObject(obj)->textureNode()->activateTexture(texData->texture(_textureName).glName() );
808 809 810 811
    PluginFunctions::triMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
  } else if ( obj->dataType( DATA_POLY_MESH ) ) {
    PolyMesh* mesh = PluginFunctions::polyMesh(obj);
    doUpdateTexture(texData->texture(_textureName), *mesh);
812 813 814
    // Texture has been bound to that object by slotAddTexture.. directly or by fileOpened from global texture
    // Just activate it
    PluginFunctions::polyMeshObject(obj)->textureNode()->activateTexture(texData->texture(_textureName).glName() );
815
    PluginFunctions::polyMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
816
  }
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( obj->dataType( DATA_HEXAHEDRAL_MESH ) ) {
    HexahedralMesh* mesh = PluginFunctions::hexahedralMesh(obj);
    HexahedralMeshObject* meshObj = PluginFunctions::hexahedralMeshObject(obj);
    doUpdateTextureOVM(texData->texture(_textureName), *mesh, *meshObj);
    // Texture has been bound to that object by slotAddTexture.. directly or by fileOpened from global texture
    // Just activate it
    PluginFunctions::hexahedralMeshObject(obj)->textureNode()->activateTexture(texData->texture(_textureName).glName() );
    PluginFunctions::hexahedralMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( obj->dataType( DATA_POLYHEDRAL_MESH ) ) {
    PolyhedralMesh* mesh = PluginFunctions::polyhedralMesh(obj);
    PolyhedralMeshObject* meshObj = PluginFunctions::polyhedralMeshObject(obj);
    doUpdateTextureOVM(texData->texture(_textureName), *mesh, *meshObj);
    // Texture has been bound to that object by slotAddTexture.. directly or by fileOpened from global texture
    // Just activate it
    PluginFunctions::polyhedralMeshObject(obj)->textureNode()->activateTexture(texData->texture(_textureName).glName() );
    PluginFunctions::polyhedralMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
  }
#endif
839

840 841 842
  // ================================================================================
  // Mark texture as not dirty
  // ================================================================================
843
  texData->texture(_textureName).clean();
844

845 846 847 848 849
  // ================================================================================
  // Tell plugins to update texture
  // ================================================================================
  emit updatedObject(obj->id(),UPDATE_TEXTURE);

850 851
}

852 853 854 855 856 857
void TextureControlPlugin::slotUpdateTexture( QString _textureName , int _identifier) {
  if ( _textureName == "Reflection Lines" )
    slotTextureUpdated( _textureName , _identifier );

}

858
template< typename MeshT >
859
void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
860
{
861

862
  if ( _texture.type() == HALFEDGEBASED ) {
863
    if (_texture.dimension() == 1) {
864 865

      OpenMesh::HPropHandleT< double > texture;
866
      if ( ! _mesh.get_property_handle(texture, _texture.name().toStdString() ) ) {
867
        emit log(LOGERR,tr("doUpdateTexture: HALFEDGEBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
868 869 870
        return;
      }

871
      copyTexture(_texture, _mesh, texture);
872

873
    } else if ( _texture.dimension() == 2 ) {
874 875

      OpenMesh::HPropHandleT< OpenMesh::Vec2d > texture2D;
876
      if ( ! _mesh.get_property_handle( texture2D, _texture.name().toStdString() ) ) {
877
        emit log(LOGERR,tr("doUpdateTexture: HALFEDGEBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
878 879 880
        return;
      }

881
      copyTexture( _texture, _mesh, texture2D);
882

883
    } else
884
      emit log(LOGERR, "doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
885
  } else if ( _texture.type() == VERTEXBASED ) {
886
    if ( _texture.dimension() == 1 ) {
887 888

      OpenMesh::VPropHandleT< double > texture;
889
      if ( ! _mesh.get_property_handle(texture,_texture.name().toStdString() ) ) {
890
        emit log(LOGERR,tr("doUpdateTexture: VERTEXBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
891
        return;
892 893
      }

894
        copyTexture(_texture, _mesh, texture);
895

896
      } else if ( _texture.dimension() == 2 ) {
897 898

        OpenMesh::VPropHandleT< OpenMesh::Vec2d >  texture2D;
899
        if ( ! _mesh.get_property_handle(texture2D,_texture.name().toStdString() ) ) {
900
          emit log(LOGERR,tr("doUpdateTexture: VERTEXBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
901
          return;
902 903
        }

904
        copyTexture( _texture, _mesh, texture2D);
905 906

      } /*else if ( textures_[_textureid].dimension == 3 ) {
907

908
        OpenMesh::VPropHandleT< OpenMesh::Vec3d >  scalarField3D;
909 910
        if ( ! _mesh.get_property_handle(scalarField3D,_texture.name) ) {
          emit log(LOGERR,"Unable to get property " + _texture.name );
911
          return;
912
        }
913

914
        copyTexture(_textureid, _mesh, scalarField3D);
915

916
      }*/ else
917
        emit log(LOGERR, "doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
918

919
    } else
920
      emit log(LOGERR, "doUpdateTexture: Unsupported Texture type");
921

922 923
}

924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939

#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
template< typename VolumeMeshT, typename VolumeMeshObjectT >
void TextureControlPlugin::doUpdateTextureOVM ( Texture& _texture, VolumeMeshT& _mesh, VolumeMeshObjectT& _obj )
{
  if ( _texture.type() == VERTEXBASED ) {
    if ( _texture.dimension() == 1 ) {

      if (!_mesh.template vertex_property_exists<double>(_texture.name().toStdString())){
        emit log(LOGERR,tr("doUpdateTexture: VERTEXBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
        return;
      }

      OpenVolumeMesh::VertexPropertyT< double > texture = _mesh.template request_vertex_property<double>(_texture.name().toStdString());
      copyTexture(_texture, _mesh, _obj, texture);

940 941
      VolumeMeshDrawModesContainer drawModesVolumeMesh;
      _obj.setObjectDrawMode(drawModesVolumeMesh.facesTextured);
942 943 944 945 946 947 948 949 950 951 952 953

    }
    else if ( _texture.dimension() == 2 )
    {

        if (!_mesh.template vertex_property_exists<ACG::Vec2d>(_texture.name().toStdString())){
          emit log(LOGERR,tr("doUpdateTexture: VERTEXBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
          return;
        }
        OpenVolumeMesh::VertexPropertyT< ACG::Vec2d > texture = _mesh.template request_vertex_property<ACG::Vec2d>(_texture.name().toStdString());
        copyTexture(_texture, _mesh, _obj, texture);

954 955
        VolumeMeshDrawModesContainer drawModesVolumeMesh;
        _obj.setObjectDrawMode(drawModesVolumeMesh.facesTextured);
956 957 958 959 960 961 962 963 964 965 966

    }
    else
      emit log(LOGERR, "doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );

  } else
    emit log(LOGERR, "doUpdateTexture: Unsupported Texture type");

}
#endif

967 968
void TextureControlPlugin::slotDrawModeChanged(int _viewerId ) {

969
#ifdef ENABLE_OPENVLUMEMESH_SUPPORT
970
  VolumeMeshDrawModesContainer drawModesVolumeMesh;
971 972
#endif

973 974
  // Only update if we have a relevant draw mode
  if (! ( ( PluginFunctions::drawMode(_viewerId) == ACG::SceneGraph::DrawModes::SOLID_TEXTURED ) ||
975
          ( PluginFunctions::drawMode(_viewerId) == ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED) ||
Jan Möbius's avatar
Jan Möbius committed
976
          ( PluginFunctions::drawMode(_viewerId) == ACG::SceneGraph::DrawModes::SOLID_2DTEXTURED_FACE) ||
977 978 979 980
          ( PluginFunctions::drawMode(_viewerId) == ACG::SceneGraph::DrawModes::SOLID_2DTEXTURED_FACE_SHADED)

#ifdef ENABLE_OPENVLUMEMESH_SUPPORT
          ||
981 982
          ( PluginFunctions::drawMode(_viewerId) &= drawModesVolumeMesh.facesTextured) ||
          ( PluginFunctions::drawMode(_viewerId) &= drawModesVolumeMesh.facesTexturedShaded)
983 984
#endif
          )) {
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
    return;
  }

  // Iterate over all Objects
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                         o_it != PluginFunctions::objectsEnd();
                                         ++o_it) {

    // Get the corresponding texture data
    TextureData* texData = dynamic_cast< TextureData* > ( o_it->objectData(TEXTUREDATA) );
    if (texData == 0){
      continue;
    }

    // Go over all textures and if one of them is enabled and dirty, update it here
    for ( uint i = 0; i < texData->textures().size(); ++i ) {
      if ( texData->textures()[i].enabled() && texData->textures()[i].dirty() ) {
        emit updateTexture( texData->textures()[i].name() , o_it->id() );
      }
    }


  }
  
  emit updateView();

1011 1012
}

Jan Möbius's avatar
Jan Möbius committed
1013
void TextureControlPlugin::slotObjectUpdated(int _identifier, const UpdateType& _type)
1014
{
1015 1016 1017
    if( !_type.contains(UPDATE_ALL) && !_type.contains(UPDATE_GEOMETRY) && !_type.contains(UPDATE_TOPOLOGY) )
        return;
    
1018 1019 1020 1021 1022
  // ================================================================================
  // Get updated object
  // ================================================================================
  if ( _identifier == -1 )
    return;
1023

1024
  BaseObjectData* obj;
1025
  if (! PluginFunctions::getObject(  _identifier , obj ) )
1026 1027
    return;

1028
  //skip object if its not a mesh
1029 1030 1031 1032 1033 1034 1035 1036
  if( !obj->dataType( DATA_TRIANGLE_MESH )   && !obj->dataType( DATA_POLY_MESH )
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
          && !obj->dataType( DATA_HEXAHEDRAL_MESH )
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
          && !obj->dataType( DATA_POLYHEDRAL_MESH )
#endif
    )
1037 1038
    return;

1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
  // ================================================================================
  // Get objects texture data and verify that texture exists
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
    return;
  }

  // ================================================================================
  // Set all textures to dirty
  // ================================================================================
  // TODO : if not in the texture rendering mode, do not emit update
  // Involves adding a interface part to react on draw mode changes
1052
  // basic check implemented
1053
  for ( uint i = 0; i < texData->textures().size(); ++i ) {
1054
    texData->textures()[i].setDirty();
1055 1056 1057 1058 1059

    bool update = false;
    for ( int j = 0 ; j < PluginFunctions::viewers() ; ++j ) {
       update |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_TEXTURED );
       update |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
Jan Möbius's avatar
Jan Möbius committed
1060 1061
       update |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_2DTEXTURED_FACE );
       update |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_2DTEXTURED_FACE_SHADED );
1062 1063 1064 1065 1066 1067

#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
       VolumeMeshDrawModesContainer ovmDrawModes;
       update |= ( PluginFunctions::drawMode(j) &= ovmDrawModes.facesTextured );
       update |= ( PluginFunctions::drawMode(j) &= ovmDrawModes.facesTexturedShaded );
#endif
1068 1069
    }

1070
    if ( update && texData->textures()[i].enabled() )
1071
      emit updateTexture( texData->textures()[i].name() , _identifier );
1072
  }
1073

1074 1075 1076
}

void TextureControlPlugin::slotUpdateAllTextures( ) {
1077 1078 1079 1080 1081 1082
  std::cerr << "slotUpdateAllTextures: not implemented yet ... might be removed" << std::endl;
  // TODO : Check
//    // Force an update of all textures which are available for the updated object
//    for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)
//       for ( uint i = 0 ; i < textures_.size() ; ++i )
//          emit updateTexture( textures_[i].name , o_it->id() );
1083 1084
}

1085
bool TextureControlPlugin::parseMode( QString _mode, Texture& _texture ) {
1086

1087
  bool changed = false;
1088

1089 1090 1091 1092 1093 1094
  int i = 0;
  QString nextString = _mode.section(',',i,i);
  while ( nextString != "" ) {
    QString sectionName = nextString.section('=',0,0);
    QString value = nextString.section('=',1,1);

1095 1096 1097
    // Cleanup representation
    value       = value.trimmed();
    sectionName = sectionName.trimmed();
Jan Möbius's avatar
Jan Möbius committed
1098
    sectionName = sectionName.toLower();
1099

1100
    if ( sectionName == "clamp" ) {
1101 1102 1103 1104 1105
      if ( StringToBool(value) != _texture.parameters.clamp ) {
        _texture.parameters.clamp = StringToBool(value);
        changed = true;
      }
    } else if ( sectionName == "clamp_max" ) {
1106 1107
      if (value.toDouble() != _texture.parameters.clampMax){
        _texture.parameters.clampMax = value.toDouble();
1108 1109 1110
        changed = true;
      }
    } else if ( sectionName == "clamp_min" ) {
1111 1112
      if (value.toDouble() != _texture.parameters.clampMin){
        _texture.parameters.clampMin = value.toDouble();
1113 1114 1115
        changed = true;
      }
    } else if ( sectionName == "max_val" ) {
1116 1117
      if (value.toDouble() != _texture.parameters.repeatMax){
        _texture.parameters.repeatMax = value.toDouble();
1118 1119
        changed = true;
      }
1120
    } else if ( sectionName == "min_val" ) {
1121 1122
      if (value.toDouble() != _texture.parameters.repeatMin){
        _texture.parameters.repeatMin = value.toDouble();
1123 1124
        changed = true;
      }
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
    } else if ( sectionName == "repeat" ) {
      if ( StringToBool(value) != _texture.parameters.repeat ) {
        _texture.parameters.repeat = StringToBool(value);
        changed = true;
      }
    } else if ( sectionName == "center" ) {
      if ( StringToBool(value) != _texture.parameters.center ) {
        _texture.parameters.center = StringToBool(value);
        changed = true;
      }
    } else if ( sectionName == "scale" ) {
      if ( StringToBool(value) != _texture.parameters.scale ) {
        _texture.parameters.scale = StringToBool(value);
        changed = true;
      }
1140 1141 1142 1143 1144 1145
    } else if ( sectionName == "abs" ) {
      if ( StringToBool(value) != _texture.parameters.abs ) {
        _texture.parameters.abs = StringToBool(value);
        changed = true;
      }
    } else if ( sectionName == "indexproperty" ) {
1146 1147 1148 1149
      if ( value != _texture.indexMappingProperty() ) {
        _texture.indexMappingProperty( value );
        changed = true;
      }
1150
    } else if ( sectionName == "visiblename" ) {
1151 1152 1153 1154
      if ( value != _texture.visibleName() ) {
        _texture.visibleName( value );
        changed = true;
      }
1155 1156 1157 1158 1159 1160 1161
    } else if ( sectionName == "type" ) {
        if ( ( value == "halfedgebased" ) && ( _texture.type() != HALFEDGEBASED ) ) {
          _texture.type( HALFEDGEBASED );
          changed = true;
        } else if ( (value == "vertexbased") && (_texture.type() != HALFEDGEBASED)  ) {
          _texture.type( VERTEXBASED );
          changed = true;
Jan Möbius's avatar
Jan Möbius committed
1162 1163 1164
        }  else if ( (value == "environmentmap") && (_texture.type() != ENVIRONMENT)  ) {
          _texture.type( ENVIRONMENT );
          changed = true;
1165
        } else {
1166
          emit log(LOGERR,"parseMode: Unknown texture type : " + value + " for texture: " + _texture.name() );
1167 1168
        }
    } else
1169
      emit log(LOGERR,"parseMode: Unknown texture mode : " + sectionName);
1170

1171 1172 1173
    ++i;
    nextString = _mode.section(',',i,i);
  }
1174

1175 1176 1177 1178 1179 1180 1181 1182 1183
  return changed;
}

void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mode) {

  // ================================================================================
  // Update texture settings for global textures
  // ================================================================================
  if ( ! globalTextures_.textureExists(_textureName) ) {