TextureControl.cc 16.6 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
  BaseObjectData* object;
Jan Möbius's avatar
   
Jan Möbius committed
81
  if (! PluginFunctions::getObject(  _identifier , object ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
82
    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
    return;

105
106
107
108
109
110
111
112
113
114
115
  QString filename = OpenFlipper::Options::textureDir().absolutePath() +
                     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
116
117
118
119

  if( object->dataType( DATA_TRIANGLE_MESH ) ) {
    TriMesh* mesh = PluginFunctions::triMesh(object);
    doUpdateTexture(textureid, *mesh);
120
121
    PluginFunctions::triMeshObject(object)->textureNode()->set_repeat(textures_[textureid].repeat);
    PluginFunctions::triMeshObject(object)->setTexture(_textureName,textureImage);
Jan Möbius's avatar
 
Jan Möbius committed
122

123
124
125
    //TODO
    //textureExists
    //enableTexture
126
  }
Jan Möbius's avatar
 
Jan Möbius committed
127
128
129
130

  if ( object->dataType( DATA_POLY_MESH ) ) {
    PolyMesh* mesh = PluginFunctions::polyMesh(object);
    doUpdateTexture(textureid, *mesh);
131
132
    PluginFunctions::polyMeshObject(object)->textureNode()->set_repeat(textures_[textureid].repeat);
    PluginFunctions::polyMeshObject(object)->setTexture(_textureName,textureImage);
Jan Möbius's avatar
 
Jan Möbius committed
133

134
135
136
    //TODO
    //textureExists
    //enableTexture
Jan Möbius's avatar
 
Jan Möbius committed
137
  }
Jan Möbius's avatar
   
Jan Möbius committed
138
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
139
140
141
142
143
144
145
146
147
148

}

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
149
	  if ( ! _mesh.get_property_handle(texture, textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
150
151
152
153
154
155
156
157
158
        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
159
	  if ( ! _mesh.get_property_handle( texture2D, textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
160
161
162
163
164
165
        emit log(LOGERR,"Unable to get property " + textures_[_textureid].name);
        return;
      }

      copyTexture(_textureid, _mesh, texture2D);

166
    } else
Jan Möbius's avatar
 
Jan Möbius committed
167
168
169
170
171
      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
172
	  if ( ! _mesh.get_property_handle(texture,textures_[_textureid].name.toStdString() ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
173
        emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
174
        return;
Jan Möbius's avatar
 
Jan Möbius committed
175
176
177
178
179
180
181
      }

        copyTexture(_textureid, _mesh, texture);

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

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

        copyTexture(_textureid, _mesh, texture2D);

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

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

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

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

Jan Möbius's avatar
 
Jan Möbius committed
202
203
    } else
      emit log(LOGERR, "Unsupported Texture type");
204

Jan Möbius's avatar
 
Jan Möbius committed
205
206
207
208
209
210
211
212
213
214
215
}

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

Jan Möbius's avatar
 
Jan Möbius committed
217
218
219
   // Use absolute value as requested by plugin
   if ( abs )
      _value = fabs(_value);
220

Jan Möbius's avatar
 
Jan Möbius committed
221
222
223
224
225
226
227
   // Clamp if requested
   if ( clamp ) {
      if ( _value > clamp_max )
         _value = clamp_max;
      if (_value < clamp_min)
         _value = clamp_min;
   }
228

Jan Möbius's avatar
 
Jan Möbius committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
   // 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)
253
{
Jan Möbius's avatar
 
Jan Möbius committed
254
255
256
257
   // Object erased, so do nothing
   if ( _identifier == -1 ) {
      return;
   }
258

Jan Möbius's avatar
 
Jan Möbius committed
259
260
261
262
   // 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 );
   }
263

Jan Möbius's avatar
 
Jan Möbius committed
264
265
266
}

void TextureControlPlugin::slotUpdateAllTextures( ) {
267
268
269
   // 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
270
271
272
273
274
275
276
277
278
279
280
         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;
        }
   }
281

Jan Möbius's avatar
 
Jan Möbius committed
282
283
284
285
   if ( textureid == -1 ) {
     emit log(LOGERR,"Texture Mode setting requested for " + _textureName + " but texture not found" );
     return;
   }
286

Jan Möbius's avatar
 
Jan Möbius committed
287
288
289
290
291
   int i = 0;
   QString nextString = _mode.section(',',i,i);
   while ( nextString != "" ) {
      QString sectionName = nextString.section('=',0,0);
      QString value = nextString.section('=',1,1);
292

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

Jan Möbius's avatar
 
Jan Möbius committed
339
340
341
      ++i;
      nextString = _mode.section(',',i,i);
   }
342

Jan Möbius's avatar
 
Jan Möbius committed
343
   if ( activeTexture_ == _textureName ) {
344
345
346

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

Jan Möbius's avatar
   
Jan Möbius committed
349
      emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
350
351
352
353
354
355
   }
}

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

357
  textureMenu_->setTearOffEnabled(true);
358
359
360

  emit addMenu( textureMenu_ , VIEWMENU );

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

Jan Möbius's avatar
 
Jan Möbius committed
363
364
365
  connect(settingsDialog_->okButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesOk() ) );
  connect(settingsDialog_->applyButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesApply() ) );
  connect(settingsDialog_->cancelButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesCancel() ) );
366

Jan Möbius's avatar
 
Jan Möbius committed
367
368
369
370
  actionGroup_ = new QActionGroup( 0 );
  actionGroup_->setExclusive( true );
  connect( actionGroup_, SIGNAL( triggered( QAction * ) ),
          this, SLOT( slotTextureMenu( QAction * ) ) );
371

Jan Möbius's avatar
 
Jan Möbius committed
372
373
374
375
  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);
376

Jan Möbius's avatar
 
Jan Möbius committed
377
378
379
  textureMenu_->addSeparator();
  textureMenu_->addActions(actionGroup_->actions());
}
380

Jan Möbius's avatar
Jan Möbius committed
381
382
383
void TextureControlPlugin::updateDialog() {
  if ( textures_.size() == 0 )
    return;
384

Jan Möbius's avatar
Jan Möbius committed
385
386
387
388
389
390
391
  int textureid = -1;
  for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
      if ( textures_[i].name == activeTexture_ ) {
            textureid = i;
            break;
      }
  }
392

Jan Möbius's avatar
 
Jan Möbius committed
393
  if ( textureid == -1 ) {
Jan Möbius's avatar
Jan Möbius committed
394
395
      emit log(LOGERR,"Active Texture not found");
      return;
Jan Möbius's avatar
 
Jan Möbius committed
396
  }
397

Jan Möbius's avatar
Jan Möbius committed
398
399
400
401
402
403
404
405
406
407
408
409
  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);

410
411
412
  // 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
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
    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
429
430
431
432

void TextureControlPlugin::slotSetTextureProperties() {
  updateDialog();
  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
  settingsDialog_->show();
}
437

Jan Möbius's avatar
 
Jan Möbius committed
438
void TextureControlPlugin::applyDialogSettings() {
Jan Möbius's avatar
Jan Möbius committed
439
  if ( textures_.size() == 0 )
Jan Möbius's avatar
 
Jan Möbius committed
440
      return;
441

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

Jan Möbius's avatar
Jan Möbius committed
450
  if (textureid == -1) {
Jan Möbius's avatar
 
Jan Möbius committed
451
      emit log(LOGERR,"Unable to get active Texture");
Jan Möbius's avatar
Jan Möbius committed
452
  }
453

Jan Möbius's avatar
Jan Möbius committed
454
455
456
457
458
  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();
459

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

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

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

Jan Möbius's avatar
Jan Möbius committed
470
471
  // 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
472
      slotTextureUpdated(  activeTexture_ , o_it->id() );
473

Jan Möbius's avatar
   
Jan Möbius committed
474
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
475
}
476

Jan Möbius's avatar
Jan Möbius committed
477
478
479
void TextureControlPlugin::slotTexturePropertiesOk() {
  applyDialogSettings();
  settingsDialog_->hide();
Jan Möbius's avatar
 
Jan Möbius committed
480
}
481

Jan Möbius's avatar
 
Jan Möbius committed
482
  void TextureControlPlugin::slotTexturePropertiesApply() {
Jan Möbius's avatar
Jan Möbius committed
483
484
    applyDialogSettings();
}
485

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

490

Jan Möbius's avatar
 
Jan Möbius committed
491
492
493
void TextureControlPlugin::slotTextureMenu(QAction* _action) {
  if ( activeTexture_ !=  _action->text() ) {
      activeTexture_ =  _action->text();
494
495
496

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

Jan Möbius's avatar
 
Jan Möbius committed
499
      updateDialog();
500

501
      PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
Jan Möbius's avatar
 
Jan Möbius committed
502
503
504
505
506
507
508
509
510
511
512
  }
}

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

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

519
  PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
520

Jan Möbius's avatar
 
Jan Möbius committed
521
522
  if ( activeTexture_ !=  _textureName ) {
    activeTexture_ =  _textureName;
523
524
525

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

Jan Möbius's avatar
 
Jan Möbius committed
528
    updateDialog();
529
530
531
532
533
534
535

    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
536
537
538
539
540
541
  }
}


Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin );