PropertyVisPlugin.cc 9.64 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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  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 with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  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 LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
 
Jan Möbius committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
//=============================================================================
//
//  CLASS PropertyVisPlugin - IMPLEMENTATION
//
//=============================================================================

//== INCLUDES =================================================================

#include <Qt>
#include <QtGui>
#include <QSpacerItem>
#include <QFileDialog>

#include "PropertyVisPlugin.hh"

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ACG/Utils/ColorCoder.hh>


//== IMPLEMENTATION ==========================================================

#define PROP_VIS "PropertyVisualization"

PropertyVisPlugin::PropertyVisPlugin() :
tool_(0),
73
propertyModel_(0)
Jan Möbius's avatar
 
Jan Möbius committed
74 75 76 77 78
{
}

void PropertyVisPlugin::initializePlugin()
{
Jan Möbius's avatar
Jan Möbius committed
79 80
  if ( OpenFlipper::Options::gui() ) {
    tool_ = new PropertyVisToolbar();
Jan Möbius's avatar
 
Jan Möbius committed
81

Jan Möbius's avatar
Jan Möbius committed
82 83
    QSize size(300,300);
    tool_->resize(size);
Jan Möbius's avatar
 
Jan Möbius committed
84

Jan Möbius's avatar
Jan Möbius committed
85 86
    // connect toolbox elements
    connect(tool_->meshNames,       SIGNAL( currentIndexChanged(int) ), this, SLOT( slotMeshChanged(int) ) );
Jan Möbius's avatar
 
Jan Möbius committed
87

Jan Möbius's avatar
Jan Möbius committed
88 89
    connect(tool_->visualizeButton, SIGNAL( clicked() ), this, SLOT( slotVisualize() ) );
    connect(tool_->clearButton,     SIGNAL( clicked() ), this, SLOT( slotAllCleared() ) );
Jan Möbius's avatar
 
Jan Möbius committed
90

Jan Möbius's avatar
Jan Möbius committed
91 92 93
    connect(tool_->refresh_property_names_tb, SIGNAL( clicked() ), this, SLOT( slotMeshChanged() ) );
    connect(tool_->duplicate_property_tb, SIGNAL( clicked() ), this, SLOT( slotDuplicateProperty() ) );
    connect(tool_->remove_property_tb, SIGNAL( clicked() ), this, SLOT( slotRemoveProperty() ) );
Jan Möbius's avatar
 
Jan Möbius committed
94

Jan Möbius's avatar
Jan Möbius committed
95
    connect(tool_, SIGNAL( widgetShown() ), this, SLOT( updateGUI() ) );
96

Jan Möbius's avatar
Jan Möbius committed
97
    tool_->meshNames->setModel(&objectListItemModel_);
98

Jan Möbius's avatar
Jan Möbius committed
99 100 101 102 103 104
    emit addHiddenPickMode( PROP_VIS );

    QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"PropertyVisIcon.png");

    emit addToolbox( tr("Property Visualization") , tool_, toolIcon );
  }
Jan Möbius's avatar
 
Jan Möbius committed
105 106 107 108 109 110 111 112 113 114 115 116
}

//-----------------------------------------------------------------------------

void PropertyVisPlugin::pluginsInitialized() 
{
}

//-----------------------------------------------------------------------------

void PropertyVisPlugin::slotPickModeChanged( const std::string& _mode)
{
117
    propertyModel_->pickModeChanged(_mode);
Jan Möbius's avatar
 
Jan Möbius committed
118 119 120 121 122 123
}

//-----------------------------------------------------------------------------

void PropertyVisPlugin::slotAllCleared()
{
124 125
    QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
    propertyModel_->clear(selectedIndices);
Jan Möbius's avatar
 
Jan Möbius committed
126

127
    emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
128 129 130 131 132 133
}

//-----------------------------------------------------------------------------

void PropertyVisPlugin::slotObjectUpdated( int _identifier, const UpdateType& _type )
{
Jan Möbius's avatar
Jan Möbius committed
134
    if( OpenFlipper::Options::gui() && tool_->isVisible() )
Jan Möbius's avatar
 
Jan Möbius committed
135 136 137
        updateGUI();
}

138
void PropertyVisPlugin::updateGUI()
Jan Möbius's avatar
 
Jan Möbius committed
139
{
140 141 142
    DataType datatype = DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH);
#ifdef ENABLE_OPENVOLUMEMESH
    datatype |= DataType(DATA_POLYHEDRAL_MESH | DATA_HEXAHEDRAL_MESH);
143
#endif
144
    objectListItemModel_.refresh(datatype);
Jan Möbius's avatar
 
Jan Möbius committed
145 146 147 148
}

//-----------------------------------------------------------------------------

149 150 151
void PropertyVisPlugin::propertySelectionChanged() {
    QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
    propertyModel_->updateWidget(selectedIndices);
Jan Möbius's avatar
 
Jan Möbius committed
152 153 154 155 156
}

//-----------------------------------------------------------------------------


157 158 159 160 161 162 163 164 165
/*! \brief Exchanges the PropertyModel after the user selected a different object.
 *
 * This method exchanges the PropertyModel after the user selects a different object
 * for visualization. The widget of the old model needs to be hidden and the one of
 * the new model is shown. Also some signals need to be disconnected and connected.
 *
 * \param id The id of the selected object
 */
void PropertyVisPlugin::setNewPropertyModel(int id)
Jan Möbius's avatar
 
Jan Möbius committed
166
{
167
    if (propertyModel_)
Jan Möbius's avatar
 
Jan Möbius committed
168
    {
169 170 171
        propertyModel_->hideWidget();
        disconnect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString)));
        disconnect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString)));
Jan Möbius's avatar
 
Jan Möbius committed
172
    }
173 174 175 176 177 178 179 180 181 182 183 184 185
    propertyModel_ = PropertyModelFactory::Instance().getModel(id);
    tool_->propertyName_lv->setModel(propertyModel_);
    connect(propertyModel_, SIGNAL( modelReset() ), this, SLOT( propertySelectionChanged() ));
    connect(tool_->propertyName_lv->selectionModel(),
            SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
            this,
            SLOT( propertySelectionChanged() ));
    QWidget* widget = propertyModel_->getWidget();
    tool_->tester->addWidget(widget);
    widget->show();
    propertyModel_->gatherProperties();
    connect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString)));
    connect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString)));
Jan Möbius's avatar
 
Jan Möbius committed
186 187 188 189
}

//-----------------------------------------------------------------------------

190
void PropertyVisPlugin::slotMeshChanged(int /*_index*/)
Jan Möbius's avatar
 
Jan Möbius committed
191 192 193 194
{
  int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
  BaseObjectData* object = 0;

195 196
  PluginFunctions::getObject( id, object );
  setNewPropertyModel(id);
Jan Möbius's avatar
 
Jan Möbius committed
197 198 199 200
}

//-----------------------------------------------------------------------------

201
void PropertyVisPlugin::slotVisualize()
Jan Möbius's avatar
 
Jan Möbius committed
202
{
203 204
    QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
    propertyModel_->visualize(selectedIndices);
Jan Möbius's avatar
 
Jan Möbius committed
205

206 207 208
    emit updateView();
    int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
    emit updatedObject( id, UPDATE_COLOR );
Jan Möbius's avatar
 
Jan Möbius committed
209 210 211 212
}

//-----------------------------------------------------------------------------

213 214
void PropertyVisPlugin::slotMouseEvent( QMouseEvent* _event ) {
    propertyModel_->mouseEvent(_event);
Jan Möbius's avatar
 
Jan Möbius committed
215 216 217 218 219 220
}

//-----------------------------------------------------------------------------

void PropertyVisPlugin::slotDuplicateProperty() {
    QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
221
    propertyModel_->duplicateProperty(selectedIndices);
Jan Möbius's avatar
 
Jan Möbius committed
222

223 224
    emit updateView();
    int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
Jan Möbius's avatar
 
Jan Möbius committed
225
    slotMeshChanged();
226
    emit updatedObject( id, UPDATE_ALL );
Jan Möbius's avatar
 
Jan Möbius committed
227 228
}

229 230
void PropertyVisPlugin::slotRemoveProperty()
{
Jan Möbius's avatar
 
Jan Möbius committed
231 232

    QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
233
    propertyModel_->removeProperty(selectedIndices);
Jan Möbius's avatar
 
Jan Möbius committed
234

235 236
    emit updateView();
    int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
Jan Möbius's avatar
 
Jan Möbius committed
237
    slotMeshChanged();
238
    emit updatedObject( id, UPDATE_ALL );
Jan Möbius's avatar
 
Jan Möbius committed
239 240 241 242
}

Q_EXPORT_PLUGIN2( propertyvisplugin , PropertyVisPlugin );