Commit e4b74494 authored by Jan Möbius's avatar Jan Möbius
Browse files

Switch Menu Entry to right Texture on update

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3583 383ad7c9-94d9-4d36-a494-682f7c89f535
parent fdee2908
......@@ -12,12 +12,12 @@
// 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.
//
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -32,13 +32,13 @@
#include <QtGui>
#include "TextureControl.hh"
#include <iostream>
#include <ACG/GL/GLState.hh>
#include <ACG/GL/GLState.hh>
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/common/GlobalOptions.hh"
......@@ -59,30 +59,30 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
tex.max_val = 1.0;
tex.type = VERTEXBASED;
textures_.push_back( tex );
activeTexture_ = _textureName;
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);
textureActions_.push_back(new_texture);
///@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 ) {
BaseObjectData* object;
if (! PluginFunctions::get_object( _identifier , object ) ) {
emit log(LOGERR,"Unable to get Object for id " + QString::number(_identifier) );
return;
}
return;
}
// Search the list of textures if we have the texture
int textureid = -1;
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
......@@ -91,39 +91,39 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
break;
}
}
if ( textureid == -1 ) {
emit log(LOGERR,"Unable to find texture with name " + _textureName );
return;
}
// Only update if the active texture is the current texture
if ( activeTexture_ != _textureName)
if ( activeTexture_ != _textureName)
return;
const bool repeat = textures_[textureid].repeat;
if( object->dataType( DATA_TRIANGLE_MESH ) ) {
TriMesh* mesh = PluginFunctions::triMesh(object);
doUpdateTexture(textureid, *mesh);
PluginFunctions::triMeshObject(object)->textureNode()->set_repeat(repeat);
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() +
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() +
textures_[textureid].filename;
PluginFunctions::triMeshObject(object)->textureNode()->read(filename.toUtf8());
}
}
if ( object->dataType( DATA_POLY_MESH ) ) {
PolyMesh* mesh = PluginFunctions::polyMesh(object);
doUpdateTexture(textureid, *mesh);
PluginFunctions::polyMeshObject(object)->textureNode()->set_repeat(repeat);
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() +
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() +
textures_[textureid].filename;
PluginFunctions::polyMeshObject(object)->textureNode()->read(filename.toUtf8());
......@@ -156,7 +156,7 @@ void TextureControlPlugin::doUpdateTexture ( int _textureid, MeshT& _mesh )
copyTexture(_textureid, _mesh, texture2D);
} else
} else
emit log(LOGERR, "Unsupported Texture Dimension " + QString::number(textures_[_textureid].dimension) );
} else if ( textures_[_textureid].type == VERTEXBASED ) {
if ( textures_[_textureid].dimension == 1 ) {
......@@ -164,7 +164,7 @@ void TextureControlPlugin::doUpdateTexture ( int _textureid, MeshT& _mesh )
OpenMesh::VPropHandleT< double > texture;
if ( ! _mesh.get_property_handle(texture,textures_[_textureid].name.toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
return;
return;
}
copyTexture(_textureid, _mesh, texture);
......@@ -174,27 +174,27 @@ void TextureControlPlugin::doUpdateTexture ( int _textureid, MeshT& _mesh )
OpenMesh::VPropHandleT< OpenMesh::Vec2d > texture2D;
if ( ! _mesh.get_property_handle(texture2D,textures_[_textureid].name.toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
return;
return;
}
copyTexture(_textureid, _mesh, texture2D);
} /*else if ( textures_[_textureid].dimension == 3 ) {
OpenMesh::VPropHandleT< OpenMesh::Vec3d > scalarField3D;
if ( ! _mesh.get_property_handle(scalarField3D,textures_[_textureid].name) ) {
emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
return;
return;
}
copyTexture(_textureid, _mesh, scalarField3D);
}*/ else
emit log(LOGERR, "Unsupported Texture Dimension " + QString::number(textures_[_textureid].dimension) );
} else
emit log(LOGERR, "Unsupported Texture type");
}
template< typename MeshT >
......@@ -218,7 +218,7 @@ void TextureControlPlugin::copyTexture ( int /*_textureid*/, MeshT& _mesh, OpenM
_mesh.set_texcoord2D( v_it, ACG::Vec2f(float(value[0]), float(value[1]) ) );
}
}
template< typename MeshT >
void TextureControlPlugin::copyTexture ( int _textureid, MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp )
{
......@@ -248,10 +248,10 @@ void TextureControlPlugin::computeMinMaxScalar(int _textureid, MeshT& _mesh,Open
const bool clamp = textures_[_textureid].clamp ;
const double clamp_max = textures_[_textureid].clamp_max;
const double clamp_min = textures_[_textureid].clamp_min;
_max = FLT_MIN;
_min = FLT_MAX;
for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin() ; v_it != _mesh.vertices_end(); ++v_it) {
if ( abs ) {
_max = std::max( fabs(_mesh.property(_texture,v_it)) , _max);
......@@ -260,8 +260,8 @@ void TextureControlPlugin::computeMinMaxScalar(int _textureid, MeshT& _mesh,Open
_max = std::max( _mesh.property(_texture,v_it) , _max);
_min = std::min( _mesh.property(_texture,v_it) , _min);
}
}
}
if ( clamp ) {
if ( _max > clamp_max )
_max = clamp_max;
......@@ -277,10 +277,10 @@ void TextureControlPlugin::computeMinMaxScalar(int _textureid, MeshT& _mesh,Open
const bool clamp = textures_[_textureid].clamp ;
const double clamp_max = textures_[_textureid].clamp_max;
const double clamp_min = textures_[_textureid].clamp_min;
_max = FLT_MIN;
_min = FLT_MAX;
for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin() ; h_it != _mesh.halfedges_end(); ++h_it) {
if ( abs ) {
_max = std::max( fabs(_mesh.property(_texture,h_it)) , _max);
......@@ -289,16 +289,16 @@ void TextureControlPlugin::computeMinMaxScalar(int _textureid, MeshT& _mesh,Open
_max = std::max( _mesh.property(_texture,h_it) , _max);
_min = std::min( _mesh.property(_texture,h_it) , _min);
}
}
}
if ( clamp ) {
if ( _max > clamp_max )
_max = clamp_max;
if (_min < clamp_min)
_min = clamp_min;
}
}
}
void TextureControlPlugin::computeValue(int _textureid, double _min, double _max, double& _value) {
const bool clamp = textures_[_textureid].clamp ;
const bool center = textures_[_textureid].center;
......@@ -308,11 +308,11 @@ void TextureControlPlugin::computeValue(int _textureid, double _min, double _max
const double clamp_min = textures_[_textureid].clamp_min;
const double scale = fabs(_max) + fabs(_min);
const bool repeat = textures_[_textureid].repeat;
// Use absolute value as requested by plugin
if ( abs )
_value = fabs(_value);
// Clamp if requested
if ( clamp ) {
if ( _value > clamp_max )
......@@ -320,7 +320,7 @@ void TextureControlPlugin::computeValue(int _textureid, double _min, double _max
if (_value < clamp_min)
_value = clamp_min;
}
// if the texture should not be repeated, scale to 0..1
if ( ! repeat ) {
if (! center ) {
......@@ -345,24 +345,24 @@ void TextureControlPlugin::computeValue(int _textureid, double _min, double _max
}
void TextureControlPlugin::slotObjectUpdated(int _identifier)
{
{
// Object erased, so do nothing
if ( _identifier == -1 ) {
return;
}
// 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 );
}
emit update_view();
}
void TextureControlPlugin::slotUpdateAllTextures( ) {
// 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 )
// 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 )
emit updateTexture( textures_[i].name , o_it->id() );
}
......@@ -374,18 +374,18 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
break;
}
}
if ( textureid == -1 ) {
emit log(LOGERR,"Texture Mode setting requested for " + _textureName + " but texture not found" );
return;
}
int i = 0;
QString nextString = _mode.section(',',i,i);
while ( nextString != "" ) {
QString sectionName = nextString.section('=',0,0);
QString value = nextString.section('=',1,1);
if ( sectionName == "clamp" ) {
if (value == "false") {
textures_[textureid].clamp = false;
......@@ -407,14 +407,14 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
textures_[textureid].repeat = false;
} else {
textures_[textureid].repeat = true;
}
}
} else
if ( sectionName == "center" ) {
if (value == "false") {
textures_[textureid].center = false;
} else {
textures_[textureid].center = true;
}
}
} else
if ( sectionName == "scale" ) {
if (value == "false") {
......@@ -431,17 +431,17 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
}
} else
emit log(LOGERR,"Unknown texture mode : " + sectionName);
++i;
nextString = _mode.section(',',i,i);
}
if ( activeTexture_ == _textureName ) {
// Force an update of all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
// Force an update of all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
updateTexture( _textureName , o_it->id() );
emit update_view();
}
}
......@@ -449,35 +449,35 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
void TextureControlPlugin::pluginsInitialized() {
// Texture menu
textureMenu_ = new QMenu(tr("&Texture Control"));
textureMenu_->setTearOffEnabled(true);
emit addMenu( textureMenu_ , VIEWMENU );
emit addMenu( textureMenu_ , VIEWMENU );
settingsDialog_ = new texturePropertiesWidget(0);
connect(settingsDialog_->okButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesOk() ) );
connect(settingsDialog_->applyButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesApply() ) );
connect(settingsDialog_->cancelButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesCancel() ) );
actionGroup_ = new QActionGroup( 0 );
actionGroup_->setExclusive( true );
connect( actionGroup_, SIGNAL( triggered( QAction * ) ),
this, SLOT( slotTextureMenu( QAction * ) ) );
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);
textureMenu_->addSeparator();
textureMenu_->addActions(actionGroup_->actions());
}
void TextureControlPlugin::updateDialog() {
if ( textures_.size() == 0 )
return;
int textureid = -1;
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
if ( textures_[i].name == activeTexture_ ) {
......@@ -485,12 +485,12 @@ void TextureControlPlugin::pluginsInitialized() {
break;
}
}
if ( textureid == -1 ) {
emit log(LOGERR,"Active Texture not found");
return;
return;
}
settingsDialog_->repeatBox->setChecked(textures_[textureid].repeat);
settingsDialog_->clampBox->setChecked(textures_[textureid].clamp);
settingsDialog_->centerBox->setChecked(textures_[textureid].center);
......@@ -501,21 +501,21 @@ void TextureControlPlugin::pluginsInitialized() {
tmp.setNum(textures_[textureid].clamp_min);
settingsDialog_->clamp_min->setText(tmp);
tmp.setNum(textures_[textureid].clamp_max);
settingsDialog_->clamp_max->setText(tmp);
settingsDialog_->clamp_max->setText(tmp);
}
void TextureControlPlugin::slotSetTextureProperties() {
updateDialog();
if ( textures_.size() == 0 )
return;
settingsDialog_->show();
}
void TextureControlPlugin::applyDialogSettings() {
if ( textures_.size() == 0 )
return;
int textureid = -1;
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
if ( textures_[i].name == activeTexture_ ) {
......@@ -523,58 +523,58 @@ void TextureControlPlugin::applyDialogSettings() {
break;
}
}
if (textureid == -1) {
emit log(LOGERR,"Unable to get active Texture");
}
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();
QString tmp;
tmp = settingsDialog_->max_val->text();
textures_[textureid].max_val = tmp.toDouble();
tmp = settingsDialog_->clamp_min->text();
textures_[textureid].clamp_min = tmp.toDouble();
tmp = settingsDialog_->clamp_max->text();
textures_[textureid].clamp_max = tmp.toDouble();
// Update the corresponding meshes
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
slotTextureUpdated( activeTexture_ , o_it->id() );
emit update_view();
}
void TextureControlPlugin::slotTexturePropertiesOk() {
applyDialogSettings();
settingsDialog_->hide();
}
void TextureControlPlugin::slotTexturePropertiesApply() {
applyDialogSettings();
}
void TextureControlPlugin::slotTexturePropertiesCancel() {
settingsDialog_->hide();
}
void TextureControlPlugin::slotTextureMenu(QAction* _action) {
if ( activeTexture_ != _action->text() ) {
activeTexture_ = _action->text();
// Force an update of all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
// Force an update of all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
slotTextureUpdated( _action->text() , o_it->id() );
updateDialog();
PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
}
}
......@@ -587,22 +587,29 @@ void TextureControlPlugin::slotSwitchTexture( QString _textureName ) {
break;
}
}
if (textureid == -1) {
emit log(LOGERR,"Unable to switch to texture " + _textureName + " (not found)");
return;
return;
}
PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
if ( activeTexture_ != _textureName ) {
activeTexture_ = _textureName;
// Force an update of all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
// Force an update of all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
slotTextureUpdated( _textureName , o_it->id() );
updateDialog();
QList<QAction *> menuEntries = actionGroup_->actions();
for ( int i = 0 ; i < menuEntries.size(); ++i ) {
if ( menuEntries[i]->text() == _textureName )
menuEntries[i]->setChecked(true);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment