TextureControl.cc 16.8 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16 17 18 19
//  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.
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




35

Jan Möbius's avatar
 
Jan Möbius committed
36 37 38 39 40
#include <QtGui>

#include "TextureControl.hh"

#include <iostream>
41
#include <ACG/GL/GLState.hh>
Jan Möbius's avatar
 
Jan Möbius committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/common/GlobalOptions.hh"

void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , uint _dimension)
{
  Texture tex;
  tex.name = _textureName;
  tex.filename = _filename;
  tex.dimension = _dimension;
  tex.scale = true;
  tex.clamp_min = FLT_MIN;
  tex.clamp_max = FLT_MAX;
  tex.clamp = false;
  tex.repeat = false;
  tex.center = false;
  tex.abs = false;
  tex.max_val = 1.0;
  tex.type = VERTEXBASED;
  textures_.push_back( tex );
62

Jan Möbius's avatar
 
Jan Möbius committed
63
  activeTexture_ = _textureName;
64

Jan Möbius's avatar
 
Jan Möbius committed
65 66 67 68 69 70
  QAction* new_texture = new QAction(_textureName, this);
  new_texture->setStatusTip(tr("Switch to this Texture"));
  new_texture->setCheckable(true);
  actionGroup_->addAction(new_texture);
  textureMenu_->addAction(new_texture);
  new_texture->setChecked(true);
71

Jan Möbius's avatar
 
Jan Möbius committed
72
  textureActions_.push_back(new_texture);
73

Jan Möbius's avatar
 
Jan Möbius committed
74 75 76 77 78
  ///@todo if a texture is added later, update or generate it for all objects
//   emit updateTexture(_textureName,-1);
}

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

Jan Möbius's avatar
 
Jan Möbius committed
80 81 82
  BaseObjectData* object;
  if (! PluginFunctions::get_object(  _identifier , object ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_identifier) );
83 84 85
    return;
  }

Jan Möbius's avatar
 
Jan Möbius committed
86 87 88 89 90 91 92 93
  // Search the list of textures if we have the texture
  int textureid = -1;
  for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
    if ( textures_[i].name == _textureName ) {
      textureid = i;
      break;
    }
  }
94 95


Jan Möbius's avatar
 
Jan Möbius committed
96 97 98 99
  if ( textureid == -1 ) {
    emit log(LOGERR,"Unable to find texture with name " + _textureName );
    return;
  }
100

Jan Möbius's avatar
 
Jan Möbius committed
101
  // Only update if the active texture is the current texture
102
  if ( activeTexture_ != _textureName)
Jan Möbius's avatar
 
Jan Möbius committed
103 104 105 106 107
    return;

  const bool repeat = textures_[textureid].repeat;

  if( object->dataType( DATA_TRIANGLE_MESH ) ) {
108

Jan Möbius's avatar
 
Jan Möbius committed
109 110 111
    TriMesh* mesh = PluginFunctions::triMesh(object);
    doUpdateTexture(textureid, *mesh);
    PluginFunctions::triMeshObject(object)->textureNode()->set_repeat(repeat);
112 113
    QString filename = OpenFlipper::Options::textureDir().absolutePath() +
      OpenFlipper::Options::dirSeparator() +
Jan Möbius's avatar
 
Jan Möbius committed
114 115 116
      textures_[textureid].filename;

    PluginFunctions::triMeshObject(object)->textureNode()->read(filename.toUtf8());
117
  }
Jan Möbius's avatar
 
Jan Möbius committed
118 119

  if ( object->dataType( DATA_POLY_MESH ) ) {
120

Jan Möbius's avatar
 
Jan Möbius committed
121 122 123 124
    PolyMesh* mesh = PluginFunctions::polyMesh(object);
    doUpdateTexture(textureid, *mesh);

    PluginFunctions::polyMeshObject(object)->textureNode()->set_repeat(repeat);
125 126
    QString filename = OpenFlipper::Options::textureDir().absolutePath() +
      OpenFlipper::Options::dirSeparator() +
Jan Möbius's avatar
 
Jan Möbius committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
      textures_[textureid].filename;

    PluginFunctions::polyMeshObject(object)->textureNode()->read(filename.toUtf8());
  }
  emit update_view();

}

template< typename MeshT >
void TextureControlPlugin::doUpdateTexture ( int _textureid, MeshT& _mesh )
{
  if ( textures_[_textureid].type == HALFEDGEBASED ) {
    if (textures_[_textureid].dimension == 1) {

      OpenMesh::HPropHandleT< double > texture;
Jan Möbius's avatar
 
Jan Möbius committed
142
	  if ( ! _mesh.get_property_handle(texture, textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
143 144 145 146 147 148 149 150 151
        emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
        return;
      }

      copyTexture(_textureid, _mesh, texture);

    } else if ( textures_[_textureid].dimension == 2 ) {

      OpenMesh::HPropHandleT< OpenMesh::Vec2d > texture2D;
Jan Möbius's avatar
 
Jan Möbius committed
152
	  if ( ! _mesh.get_property_handle( texture2D, textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
153 154 155 156 157 158
        emit log(LOGERR,"Unable to get property " + textures_[_textureid].name);
        return;
      }

      copyTexture(_textureid, _mesh, texture2D);

159
    } else
Jan Möbius's avatar
 
Jan Möbius committed
160 161 162 163 164
      emit log(LOGERR, "Unsupported Texture Dimension " + QString::number(textures_[_textureid].dimension) );
  } else if ( textures_[_textureid].type == VERTEXBASED ) {
    if ( textures_[_textureid].dimension == 1 ) {

      OpenMesh::VPropHandleT< double > texture;
Jan Möbius's avatar
 
Jan Möbius committed
165
	  if ( ! _mesh.get_property_handle(texture,textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
166
        emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
167
        return;
Jan Möbius's avatar
 
Jan Möbius committed
168 169 170 171 172 173 174
      }

        copyTexture(_textureid, _mesh, texture);

      } else if ( textures_[_textureid].dimension == 2 ) {

        OpenMesh::VPropHandleT< OpenMesh::Vec2d >  texture2D;
Jan Möbius's avatar
Jan Möbius committed
175
		  if ( ! _mesh.get_property_handle(texture2D,textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
176
          emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
177
          return;
Jan Möbius's avatar
 
Jan Möbius committed
178 179 180 181 182
        }

        copyTexture(_textureid, _mesh, texture2D);

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

Jan Möbius's avatar
 
Jan Möbius committed
184
        OpenMesh::VPropHandleT< OpenMesh::Vec3d >  scalarField3D;
Jan Möbius's avatar
 
Jan Möbius committed
185
        if ( ! _mesh.get_property_handle(scalarField3D,textures_[_textureid].name) ) {
Jan Möbius's avatar
 
Jan Möbius committed
186
          emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
187
          return;
Jan Möbius's avatar
 
Jan Möbius committed
188
        }
189

Jan Möbius's avatar
 
Jan Möbius committed
190
        copyTexture(_textureid, _mesh, scalarField3D);
191

Jan Möbius's avatar
 
Jan Möbius committed
192 193
      }*/ else
        emit log(LOGERR, "Unsupported Texture Dimension " + QString::number(textures_[_textureid].dimension) );
194

Jan Möbius's avatar
 
Jan Möbius committed
195 196
    } else
      emit log(LOGERR, "Unsupported Texture type");
197

Jan Möbius's avatar
 
Jan Möbius committed
198 199 200 201 202 203 204 205 206 207 208
}

void TextureControlPlugin::computeValue(int _textureid, double _min, double _max, double& _value) {
   const bool clamp = textures_[_textureid].clamp ;
   const bool center = textures_[_textureid].center;
   const double max_val = textures_[_textureid].max_val;
   const bool abs = textures_[_textureid].abs;
   const double clamp_max = textures_[_textureid].clamp_max;
   const double clamp_min = textures_[_textureid].clamp_min;
   const double scale = fabs(_max) + fabs(_min);
   const bool repeat = textures_[_textureid].repeat;
209

Jan Möbius's avatar
 
Jan Möbius committed
210 211 212
   // Use absolute value as requested by plugin
   if ( abs )
      _value = fabs(_value);
213

Jan Möbius's avatar
 
Jan Möbius committed
214 215 216 217 218 219 220
   // Clamp if requested
   if ( clamp ) {
      if ( _value > clamp_max )
         _value = clamp_max;
      if (_value < clamp_min)
         _value = clamp_min;
   }
221

Jan Möbius's avatar
 
Jan Möbius committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
   // if the texture should not be repeated, scale to 0..1
   if ( ! repeat ) {
      if (! center ) {
        if ( textures_[_textureid].scale) {
          _value /= scale;
          _value -= _min/scale;
        }
      } else {
         // the values above zero are mapped to 0.5..1 the negative ones to 0.5..0
         if (_value > 0.0) {
            _value /= ( _max * 2.0);
            _value += 0.5;
         } else {
            _value /= ( _min * 2.0);
            _value = 0.5 - _value;
         }
      }
   } else {
      _value -= _min;
      _value *= max_val / (_max - _min);
   }
}

void TextureControlPlugin::slotObjectUpdated(int _identifier)
246
{
Jan Möbius's avatar
 
Jan Möbius committed
247 248 249 250
   // Object erased, so do nothing
   if ( _identifier == -1 ) {
      return;
   }
251

Jan Möbius's avatar
 
Jan Möbius committed
252 253 254 255
   // Force an update of all textures which are available for the updated object
   for ( uint i = 0 ; i < textures_.size() ; ++i ) {
      emit updateTexture( textures_[i].name , _identifier );
   }
256

Jan Möbius's avatar
 
Jan Möbius committed
257 258 259 260
   emit update_view();
}

void TextureControlPlugin::slotUpdateAllTextures( ) {
261 262 263
   // Force an update of all textures which are available for the updated object
   for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
      for ( uint i = 0 ; i < textures_.size() ; ++i )
Jan Möbius's avatar
 
Jan Möbius committed
264 265 266 267 268 269 270 271 272 273 274
         emit updateTexture( textures_[i].name , o_it->id() );
}

void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mode) {
   int textureid = -1;
   for ( int j = 0 ; j < (int)textures_.size() ; ++j ) {
        if ( textures_[j].name == _textureName ) {
             textureid = j;
             break;
        }
   }
275

Jan Möbius's avatar
 
Jan Möbius committed
276 277 278 279
   if ( textureid == -1 ) {
     emit log(LOGERR,"Texture Mode setting requested for " + _textureName + " but texture not found" );
     return;
   }
280

Jan Möbius's avatar
 
Jan Möbius committed
281 282 283 284 285
   int i = 0;
   QString nextString = _mode.section(',',i,i);
   while ( nextString != "" ) {
      QString sectionName = nextString.section('=',0,0);
      QString value = nextString.section('=',1,1);
286

Jan Möbius's avatar
 
Jan Möbius committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
      if ( sectionName == "clamp" ) {
         if (value == "false") {
              textures_[textureid].clamp = false;
         } else {
              textures_[textureid].clamp = true;
         }
      } else
      if ( sectionName == "clamp_max" ) {
              textures_[textureid].clamp_max = value.toDouble();
      } else
      if ( sectionName == "clamp_min" ) {
              textures_[textureid].clamp_min = value.toDouble();
      } else
      if ( sectionName == "max_val" ) {
              textures_[textureid].max_val = value.toDouble();
      } else
      if ( sectionName == "repeat" ) {
         if (value == "false") {
              textures_[textureid].repeat = false;
         } else {
              textures_[textureid].repeat = true;
308
         }
Jan Möbius's avatar
 
Jan Möbius committed
309 310 311 312 313 314
      } else
      if ( sectionName == "center" ) {
         if (value == "false") {
              textures_[textureid].center = false;
         } else {
              textures_[textureid].center = true;
315
         }
Jan Möbius's avatar
 
Jan Möbius committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
      } else
      if ( sectionName == "scale" ) {
         if (value == "false") {
              textures_[textureid].scale = false;
         } else {
              textures_[textureid].scale = true;
         }
      } else
      if ( sectionName == "type" ) {
         if (value == "halfedgebased") {
              textures_[textureid].type = HALFEDGEBASED;
         } else {
              textures_[textureid].type = VERTEXBASED;
         }
      } else
        emit log(LOGERR,"Unknown texture mode : " + sectionName);
332

Jan Möbius's avatar
 
Jan Möbius committed
333 334 335
      ++i;
      nextString = _mode.section(',',i,i);
   }
336

Jan Möbius's avatar
 
Jan Möbius committed
337
   if ( activeTexture_ == _textureName ) {
338 339 340

      // Force an update of all objects
      for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
Jan Möbius's avatar
 
Jan Möbius committed
341
         updateTexture(  _textureName , o_it->id() );
342

Jan Möbius's avatar
 
Jan Möbius committed
343 344 345 346 347 348 349
      emit update_view();
   }
}

void TextureControlPlugin::pluginsInitialized() {
  // Texture menu
  textureMenu_ = new QMenu(tr("&Texture Control"));
350

351
  textureMenu_->setTearOffEnabled(true);
352 353 354

  emit addMenu( textureMenu_ , VIEWMENU );

Jan Möbius's avatar
 
Jan Möbius committed
355
  settingsDialog_ = new texturePropertiesWidget(0);
356

Jan Möbius's avatar
 
Jan Möbius committed
357 358 359
  connect(settingsDialog_->okButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesOk() ) );
  connect(settingsDialog_->applyButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesApply() ) );
  connect(settingsDialog_->cancelButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesCancel() ) );
360

Jan Möbius's avatar
 
Jan Möbius committed
361 362 363 364
  actionGroup_ = new QActionGroup( 0 );
  actionGroup_->setExclusive( true );
  connect( actionGroup_, SIGNAL( triggered( QAction * ) ),
          this, SLOT( slotTextureMenu( QAction * ) ) );
365

Jan Möbius's avatar
 
Jan Möbius committed
366 367 368 369
  QAction* AC_Texture_Settings = new QAction(tr("&Texture Settings"), this);
  AC_Texture_Settings->setStatusTip(tr("Set the texture visualization properties"));
  connect(AC_Texture_Settings, SIGNAL(triggered()), this, SLOT(slotSetTextureProperties()));
  textureMenu_->addAction(AC_Texture_Settings);
370

Jan Möbius's avatar
 
Jan Möbius committed
371 372 373
  textureMenu_->addSeparator();
  textureMenu_->addActions(actionGroup_->actions());
}
374

Jan Möbius's avatar
Jan Möbius committed
375 376 377
void TextureControlPlugin::updateDialog() {
  if ( textures_.size() == 0 )
    return;
378

Jan Möbius's avatar
Jan Möbius committed
379 380 381 382 383 384 385
  int textureid = -1;
  for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
      if ( textures_[i].name == activeTexture_ ) {
            textureid = i;
            break;
      }
  }
386

Jan Möbius's avatar
 
Jan Möbius committed
387
  if ( textureid == -1 ) {
Jan Möbius's avatar
Jan Möbius committed
388 389
      emit log(LOGERR,"Active Texture not found");
      return;
Jan Möbius's avatar
 
Jan Möbius committed
390
  }
391

Jan Möbius's avatar
Jan Möbius committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
  settingsDialog_->repeatBox->setChecked(textures_[textureid].repeat);
  settingsDialog_->clampBox->setChecked(textures_[textureid].clamp);
  settingsDialog_->centerBox->setChecked(textures_[textureid].center);
  settingsDialog_->absBox->setChecked(textures_[textureid].abs);
  QString tmp;
  tmp.setNum(textures_[textureid].max_val);
  settingsDialog_->max_val->setText( tmp );
  tmp.setNum(textures_[textureid].clamp_min);
  settingsDialog_->clamp_min->setText(tmp);
  tmp.setNum(textures_[textureid].clamp_max);
  settingsDialog_->clamp_max->setText(tmp);

//   // update plot only when dimension is 1
//   if ( textures_[textureid].dimension == 1) {
//     std::vector< double > x,y;
//
// //     getOriginalHistogram();
//
//   }
}

// template< typename MeshT >
// void TextureControlPlugin::getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
//                                                 int _textureid, MeshT& _mesh,
//                                                 OpenMesh::VPropHandleT< double > _texProp) {
//   _x.clear();
//   _y.clear();
//
//   for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
//     double value = _mesh.property(_texProp, v_it);
//   }
//
// }

void TextureControlPlugin::slotSetTextureProperties() {
  updateDialog();
  if ( textures_.size() == 0 )
Jan Möbius's avatar
 
Jan Möbius committed
429
      return;
430

Jan Möbius's avatar
Jan Möbius committed
431 432
  settingsDialog_->show();
}
433

Jan Möbius's avatar
 
Jan Möbius committed
434
void TextureControlPlugin::applyDialogSettings() {
Jan Möbius's avatar
Jan Möbius committed
435
  if ( textures_.size() == 0 )
Jan Möbius's avatar
 
Jan Möbius committed
436
      return;
437

Jan Möbius's avatar
Jan Möbius committed
438 439 440 441 442 443 444
  int textureid = -1;
  for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
        if ( textures_[i].name == activeTexture_ ) {
              textureid = i;
              break;
        }
  }
445

Jan Möbius's avatar
Jan Möbius committed
446
  if (textureid == -1) {
Jan Möbius's avatar
 
Jan Möbius committed
447
      emit log(LOGERR,"Unable to get active Texture");
Jan Möbius's avatar
Jan Möbius committed
448
  }
449

Jan Möbius's avatar
Jan Möbius committed
450 451 452 453 454
  textures_[textureid].repeat=settingsDialog_->repeatBox->isChecked();
  textures_[textureid].clamp=settingsDialog_->clampBox->isChecked();
  textures_[textureid].center=settingsDialog_->centerBox->isChecked();
  textures_[textureid].abs=settingsDialog_->absBox->isChecked();
  textures_[textureid].scale=settingsDialog_->scaleBox->isChecked();
455

Jan Möbius's avatar
Jan Möbius committed
456 457 458
  QString tmp;
  tmp = settingsDialog_->max_val->text();
  textures_[textureid].max_val = tmp.toDouble();
459

Jan Möbius's avatar
Jan Möbius committed
460 461
  tmp = settingsDialog_->clamp_min->text();
  textures_[textureid].clamp_min = tmp.toDouble();
462

Jan Möbius's avatar
Jan Möbius committed
463 464
  tmp = settingsDialog_->clamp_max->text();
  textures_[textureid].clamp_max = tmp.toDouble();
465

Jan Möbius's avatar
Jan Möbius committed
466 467
  // Update the corresponding meshes
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
Jan Möbius's avatar
 
Jan Möbius committed
468
      slotTextureUpdated(  activeTexture_ , o_it->id() );
469

Jan Möbius's avatar
Jan Möbius committed
470
  emit update_view();
Jan Möbius's avatar
 
Jan Möbius committed
471
}
472

Jan Möbius's avatar
Jan Möbius committed
473 474 475
void TextureControlPlugin::slotTexturePropertiesOk() {
  applyDialogSettings();
  settingsDialog_->hide();
Jan Möbius's avatar
 
Jan Möbius committed
476
}
477

Jan Möbius's avatar
 
Jan Möbius committed
478
  void TextureControlPlugin::slotTexturePropertiesApply() {
Jan Möbius's avatar
Jan Möbius committed
479 480
    applyDialogSettings();
}
481

Jan Möbius's avatar
Jan Möbius committed
482
void TextureControlPlugin::slotTexturePropertiesCancel() {
Jan Möbius's avatar
 
Jan Möbius committed
483
    settingsDialog_->hide();
Jan Möbius's avatar
Jan Möbius committed
484
}
Jan Möbius's avatar
 
Jan Möbius committed
485

486

Jan Möbius's avatar
 
Jan Möbius committed
487 488 489
void TextureControlPlugin::slotTextureMenu(QAction* _action) {
  if ( activeTexture_ !=  _action->text() ) {
      activeTexture_ =  _action->text();
490 491 492

      // Force an update of all objects
      for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
Jan Möbius's avatar
Jan Möbius committed
493
        slotTextureUpdated(  _action->text() , o_it->id() );
494

Jan Möbius's avatar
 
Jan Möbius committed
495
      updateDialog();
496

497
      PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
Jan Möbius's avatar
 
Jan Möbius committed
498 499 500 501 502 503 504 505 506 507 508
  }
}

void TextureControlPlugin::slotSwitchTexture( QString _textureName ) {
  int textureid = -1;
  for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
        if ( textures_[i].name == _textureName ) {
              textureid = i;
              break;
        }
  }
509

Jan Möbius's avatar
 
Jan Möbius committed
510 511
  if (textureid == -1) {
    emit log(LOGERR,"Unable to switch to texture " + _textureName + " (not found)");
512
    return;
Jan Möbius's avatar
 
Jan Möbius committed
513
  }
514

515
  PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
516

Jan Möbius's avatar
 
Jan Möbius committed
517 518
  if ( activeTexture_ !=  _textureName ) {
    activeTexture_ =  _textureName;
519 520 521

    // Force an update of all objects
    for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
Jan Möbius's avatar
 
Jan Möbius committed
522
        slotTextureUpdated(  _textureName , o_it->id() );
523

Jan Möbius's avatar
 
Jan Möbius committed
524
    updateDialog();
525 526 527 528 529 530 531

    QList<QAction *> menuEntries = actionGroup_->actions();

    for ( int i = 0 ; i < menuEntries.size(); ++i ) {
      if ( menuEntries[i]->text() == _textureName )
        menuEntries[i]->setChecked(true);
    }
Jan Möbius's avatar
 
Jan Möbius committed
532 533 534 535 536 537
  }
}


Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin );