TextureControl.cc 16.5 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
      textures_[textureid].filename;

    PluginFunctions::polyMeshObject(object)->textureNode()->read(filename.toUtf8());
  }
Jan Möbius's avatar
 
Jan Möbius committed
131
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
132 133 134 135 136 137 138 139 140 141

}

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
}

void TextureControlPlugin::slotUpdateAllTextures( ) {
260 261 262
   // 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
263 264 265 266 267 268 269 270 271 272 273
         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;
        }
   }
274

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

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

Jan Möbius's avatar
 
Jan Möbius committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
      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;
307
         }
Jan Möbius's avatar
 
Jan Möbius committed
308 309 310 311 312 313
      } else
      if ( sectionName == "center" ) {
         if (value == "false") {
              textures_[textureid].center = false;
         } else {
              textures_[textureid].center = true;
314
         }
Jan Möbius's avatar
 
Jan Möbius committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
      } 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);
331

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

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

      // 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
340
         updateTexture(  _textureName , o_it->id() );
341

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

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

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

  emit addMenu( textureMenu_ , VIEWMENU );

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

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

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

Jan Möbius's avatar
 
Jan Möbius committed
365 366 367 368
  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);
369

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

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

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

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

Jan Möbius's avatar
Jan Möbius committed
391 392 393 394 395 396 397 398 399 400 401 402
  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);

403 404 405
  // update plot only when dimension is 1
  if ( textures_[textureid].dimension == 1) {
    std::vector< double > x,y;
Jan Möbius's avatar
Jan Möbius committed
406

407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    x.push_back(100.0);
    y.push_back(100.0);

    x.push_back(200.0);
    y.push_back(150.0);

    x.push_back(300.0);
    y.push_back(10.0);

    settingsDialog_->setOriginalData(x,y);

//     getOriginalHistogram();

  }
}
Jan Möbius's avatar
Jan Möbius committed
422 423 424 425

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

Jan Möbius's avatar
Jan Möbius committed
428 429
  settingsDialog_->show();
}
430

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

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

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

Jan Möbius's avatar
Jan Möbius committed
447 448 449 450 451
  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();
452

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

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

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

Jan Möbius's avatar
Jan Möbius committed
463 464
  // 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
465
      slotTextureUpdated(  activeTexture_ , o_it->id() );
466

Jan Möbius's avatar
 
Jan Möbius committed
467
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
468
}
469

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

Jan Möbius's avatar
 
Jan Möbius committed
475
  void TextureControlPlugin::slotTexturePropertiesApply() {
Jan Möbius's avatar
Jan Möbius committed
476 477
    applyDialogSettings();
}
478

Jan Möbius's avatar
Jan Möbius committed
479
void TextureControlPlugin::slotTexturePropertiesCancel() {
Jan Möbius's avatar
 
Jan Möbius committed
480
    settingsDialog_->hide();
Jan Möbius's avatar
Jan Möbius committed
481
}
Jan Möbius's avatar
 
Jan Möbius committed
482

483

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

      // 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
490
        slotTextureUpdated(  _action->text() , o_it->id() );
491

Jan Möbius's avatar
 
Jan Möbius committed
492
      updateDialog();
493

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

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;
        }
  }
506

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

512
  PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
513

Jan Möbius's avatar
 
Jan Möbius committed
514 515
  if ( activeTexture_ !=  _textureName ) {
    activeTexture_ =  _textureName;
516 517 518

    // 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
519
        slotTextureUpdated(  _textureName , o_it->id() );
520

Jan Möbius's avatar
 
Jan Möbius committed
521
    updateDialog();
522 523 524 525 526 527 528

    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
529 530 531 532 533 534
  }
}


Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin );