TextureControl.cc 16.9 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
    QString filename = OpenFlipper::Options::textureDir().absolutePath() +
113 114 115 116 117 118 119 120 121 122
                       OpenFlipper::Options::dirSeparator() +
                       textures_[textureid].filename;

       // load to image
    QImage textureImage;
    if ( !textureImage.load( filename ) )
    {
        std::cerr << "Cannot load texture " << filename.toStdString() << "\n";
        return ;
    }
Jan Möbius's avatar
 
Jan Möbius committed
123

124
    PluginFunctions::triMeshObject(object)->addTexture(_textureName,textureImage);
125
  }
Jan Möbius's avatar
 
Jan Möbius committed
126 127

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

Jan Möbius's avatar
 
Jan Möbius committed
129 130 131 132
    PolyMesh* mesh = PluginFunctions::polyMesh(object);
    doUpdateTexture(textureid, *mesh);

    PluginFunctions::polyMeshObject(object)->textureNode()->set_repeat(repeat);
133
    QString filename = OpenFlipper::Options::textureDir().absolutePath() +
134 135 136 137 138 139 140 141 142 143
                       OpenFlipper::Options::dirSeparator() +
                       textures_[textureid].filename;

    // load to image
    QImage textureImage;
    if ( !textureImage.load( filename ) )
    {
        std::cerr << "Cannot load texture " << filename.toStdString() << "\n";
        return ;
    }
Jan Möbius's avatar
 
Jan Möbius committed
144

145
    PluginFunctions::polyMeshObject(object)->addTexture(_textureName,textureImage);
Jan Möbius's avatar
 
Jan Möbius committed
146
  }
Jan Möbius's avatar
 
Jan Möbius committed
147
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
148 149 150 151 152 153 154 155 156 157

}

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
158
	  if ( ! _mesh.get_property_handle(texture, textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
159 160 161 162 163 164 165 166 167
        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
168
	  if ( ! _mesh.get_property_handle( texture2D, textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
169 170 171 172 173 174
        emit log(LOGERR,"Unable to get property " + textures_[_textureid].name);
        return;
      }

      copyTexture(_textureid, _mesh, texture2D);

175
    } else
Jan Möbius's avatar
 
Jan Möbius committed
176 177 178 179 180
      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
181
	  if ( ! _mesh.get_property_handle(texture,textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
182
        emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
183
        return;
Jan Möbius's avatar
 
Jan Möbius committed
184 185 186 187 188 189 190
      }

        copyTexture(_textureid, _mesh, texture);

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

        OpenMesh::VPropHandleT< OpenMesh::Vec2d >  texture2D;
Jan Möbius's avatar
Jan Möbius committed
191
		  if ( ! _mesh.get_property_handle(texture2D,textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
192
          emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
193
          return;
Jan Möbius's avatar
 
Jan Möbius committed
194 195 196 197 198
        }

        copyTexture(_textureid, _mesh, texture2D);

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

Jan Möbius's avatar
 
Jan Möbius committed
200
        OpenMesh::VPropHandleT< OpenMesh::Vec3d >  scalarField3D;
Jan Möbius's avatar
 
Jan Möbius committed
201
        if ( ! _mesh.get_property_handle(scalarField3D,textures_[_textureid].name) ) {
Jan Möbius's avatar
 
Jan Möbius committed
202
          emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
203
          return;
Jan Möbius's avatar
 
Jan Möbius committed
204
        }
205

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

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

Jan Möbius's avatar
 
Jan Möbius committed
211 212
    } else
      emit log(LOGERR, "Unsupported Texture type");
213

Jan Möbius's avatar
 
Jan Möbius committed
214 215 216 217 218 219 220 221 222 223 224
}

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;
225

Jan Möbius's avatar
 
Jan Möbius committed
226 227 228
   // Use absolute value as requested by plugin
   if ( abs )
      _value = fabs(_value);
229

Jan Möbius's avatar
 
Jan Möbius committed
230 231 232 233 234 235 236
   // Clamp if requested
   if ( clamp ) {
      if ( _value > clamp_max )
         _value = clamp_max;
      if (_value < clamp_min)
         _value = clamp_min;
   }
237

Jan Möbius's avatar
 
Jan Möbius committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
   // 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)
262
{
Jan Möbius's avatar
 
Jan Möbius committed
263 264 265 266
   // Object erased, so do nothing
   if ( _identifier == -1 ) {
      return;
   }
267

Jan Möbius's avatar
 
Jan Möbius committed
268 269 270 271
   // 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 );
   }
272

Jan Möbius's avatar
 
Jan Möbius committed
273 274 275
}

void TextureControlPlugin::slotUpdateAllTextures( ) {
276 277 278
   // 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
279 280 281 282 283 284 285 286 287 288 289
         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;
        }
   }
290

Jan Möbius's avatar
 
Jan Möbius committed
291 292 293 294
   if ( textureid == -1 ) {
     emit log(LOGERR,"Texture Mode setting requested for " + _textureName + " but texture not found" );
     return;
   }
295

Jan Möbius's avatar
 
Jan Möbius committed
296 297 298 299 300
   int i = 0;
   QString nextString = _mode.section(',',i,i);
   while ( nextString != "" ) {
      QString sectionName = nextString.section('=',0,0);
      QString value = nextString.section('=',1,1);
301

Jan Möbius's avatar
 
Jan Möbius committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
      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;
323
         }
Jan Möbius's avatar
 
Jan Möbius committed
324 325 326 327 328 329
      } else
      if ( sectionName == "center" ) {
         if (value == "false") {
              textures_[textureid].center = false;
         } else {
              textures_[textureid].center = true;
330
         }
Jan Möbius's avatar
 
Jan Möbius committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
      } 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);
347

Jan Möbius's avatar
 
Jan Möbius committed
348 349 350
      ++i;
      nextString = _mode.section(',',i,i);
   }
351

Jan Möbius's avatar
 
Jan Möbius committed
352
   if ( activeTexture_ == _textureName ) {
353 354 355

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

Jan Möbius's avatar
 
Jan Möbius committed
358
      emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
359 360 361 362 363 364
   }
}

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

366
  textureMenu_->setTearOffEnabled(true);
367 368 369

  emit addMenu( textureMenu_ , VIEWMENU );

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

Jan Möbius's avatar
 
Jan Möbius committed
372 373 374
  connect(settingsDialog_->okButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesOk() ) );
  connect(settingsDialog_->applyButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesApply() ) );
  connect(settingsDialog_->cancelButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesCancel() ) );
375

Jan Möbius's avatar
 
Jan Möbius committed
376 377 378 379
  actionGroup_ = new QActionGroup( 0 );
  actionGroup_->setExclusive( true );
  connect( actionGroup_, SIGNAL( triggered( QAction * ) ),
          this, SLOT( slotTextureMenu( QAction * ) ) );
380

Jan Möbius's avatar
 
Jan Möbius committed
381 382 383 384
  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);
385

Jan Möbius's avatar
 
Jan Möbius committed
386 387 388
  textureMenu_->addSeparator();
  textureMenu_->addActions(actionGroup_->actions());
}
389

Jan Möbius's avatar
Jan Möbius committed
390 391 392
void TextureControlPlugin::updateDialog() {
  if ( textures_.size() == 0 )
    return;
393

Jan Möbius's avatar
Jan Möbius committed
394 395 396 397 398 399 400
  int textureid = -1;
  for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
      if ( textures_[i].name == activeTexture_ ) {
            textureid = i;
            break;
      }
  }
401

Jan Möbius's avatar
 
Jan Möbius committed
402
  if ( textureid == -1 ) {
Jan Möbius's avatar
Jan Möbius committed
403 404
      emit log(LOGERR,"Active Texture not found");
      return;
Jan Möbius's avatar
 
Jan Möbius committed
405
  }
406

Jan Möbius's avatar
Jan Möbius committed
407 408 409 410 411 412 413 414 415 416 417 418
  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);

419 420 421
  // 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
422

423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
    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
438 439 440 441

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

Jan Möbius's avatar
Jan Möbius committed
444 445
  settingsDialog_->show();
}
446

Jan Möbius's avatar
 
Jan Möbius committed
447
void TextureControlPlugin::applyDialogSettings() {
Jan Möbius's avatar
Jan Möbius committed
448
  if ( textures_.size() == 0 )
Jan Möbius's avatar
 
Jan Möbius committed
449
      return;
450

Jan Möbius's avatar
Jan Möbius committed
451 452 453 454 455 456 457
  int textureid = -1;
  for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
        if ( textures_[i].name == activeTexture_ ) {
              textureid = i;
              break;
        }
  }
458

Jan Möbius's avatar
Jan Möbius committed
459
  if (textureid == -1) {
Jan Möbius's avatar
 
Jan Möbius committed
460
      emit log(LOGERR,"Unable to get active Texture");
Jan Möbius's avatar
Jan Möbius committed
461
  }
462

Jan Möbius's avatar
Jan Möbius committed
463 464 465 466 467
  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();
468

Jan Möbius's avatar
Jan Möbius committed
469 470 471
  QString tmp;
  tmp = settingsDialog_->max_val->text();
  textures_[textureid].max_val = tmp.toDouble();
472

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

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

Jan Möbius's avatar
Jan Möbius committed
479 480
  // 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
481
      slotTextureUpdated(  activeTexture_ , o_it->id() );
482

Jan Möbius's avatar
 
Jan Möbius committed
483
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
484
}
485

Jan Möbius's avatar
Jan Möbius committed
486 487 488
void TextureControlPlugin::slotTexturePropertiesOk() {
  applyDialogSettings();
  settingsDialog_->hide();
Jan Möbius's avatar
 
Jan Möbius committed
489
}
490

Jan Möbius's avatar
 
Jan Möbius committed
491
  void TextureControlPlugin::slotTexturePropertiesApply() {
Jan Möbius's avatar
Jan Möbius committed
492 493
    applyDialogSettings();
}
494

Jan Möbius's avatar
Jan Möbius committed
495
void TextureControlPlugin::slotTexturePropertiesCancel() {
Jan Möbius's avatar
 
Jan Möbius committed
496
    settingsDialog_->hide();
Jan Möbius's avatar
Jan Möbius committed
497
}
Jan Möbius's avatar
 
Jan Möbius committed
498

499

Jan Möbius's avatar
 
Jan Möbius committed
500 501 502
void TextureControlPlugin::slotTextureMenu(QAction* _action) {
  if ( activeTexture_ !=  _action->text() ) {
      activeTexture_ =  _action->text();
503 504 505

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

Jan Möbius's avatar
 
Jan Möbius committed
508
      updateDialog();
509

510
      PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
Jan Möbius's avatar
 
Jan Möbius committed
511 512 513 514 515 516 517 518 519 520 521
  }
}

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

Jan Möbius's avatar
 
Jan Möbius committed
523 524
  if (textureid == -1) {
    emit log(LOGERR,"Unable to switch to texture " + _textureName + " (not found)");
525
    return;
Jan Möbius's avatar
 
Jan Möbius committed
526
  }
527

528
  PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
529

Jan Möbius's avatar
 
Jan Möbius committed
530 531
  if ( activeTexture_ !=  _textureName ) {
    activeTexture_ =  _textureName;
532 533 534

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

Jan Möbius's avatar
 
Jan Möbius committed
537
    updateDialog();
538 539 540 541 542 543 544

    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
545 546 547 548 549 550
  }
}


Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin );