Developer Documentation
PropertyVisPlugin.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 //=============================================================================
51 //
52 // CLASS PropertyVisPlugin - IMPLEMENTATION
53 //
54 //=============================================================================
55 
56 //== INCLUDES =================================================================
57 
58 #include "PropertyVisPlugin.hh"
59 
60 #include "PropertyModelFactory.hh"
61 
62 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
64 #endif
65 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
67 #endif
68 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
70 #endif
71 
72 //== IMPLEMENTATION ==========================================================
73 
74 #define PROP_VIS "PropertyVisualization"
75 
76 PropertyVisPlugin::PropertyVisPlugin() :
77 tool_(0),
78 propertyModel_(0)
79 {
80 }
81 
82 void PropertyVisPlugin::initializePlugin()
83 {
84  if ( OpenFlipper::Options::gui() ) {
85  tool_ = new PropertyVisToolbar();
86 
87  QSize size(300,300);
88  tool_->resize(size);
89 
90  tool_->meshNames->setModel(&objectListItemModel_);
91 
92  emit addHiddenPickMode( PROP_VIS );
93 
94  QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"PropertyVisIcon.png");
95 
96  emit addToolbox( tr("Property Visualization") , tool_, toolIcon );
97  }
98 }
99 
100 //-----------------------------------------------------------------------------
101 
102 void PropertyVisPlugin::pluginsInitialized()
103 {
104  if ( OpenFlipper::Options::gui() ) {
105 
106  // connect toolbox elements
107  connect(tool_->meshNames, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotMeshChanged(int) ) );
108 
109  connect(tool_->visualizeButton, SIGNAL( clicked() ), this, SLOT( slotVisualize() ) );
110  connect(tool_->clearButton, SIGNAL( clicked() ), this, SLOT( slotAllCleared() ) );
111 
112  connect(tool_->refresh_property_names_tb, SIGNAL( clicked() ), this, SLOT( slotMeshChanged() ) );
113  connect(tool_->duplicate_property_tb, SIGNAL( clicked() ), this, SLOT( slotDuplicateProperty() ) );
114  connect(tool_->remove_property_tb, SIGNAL( clicked() ), this, SLOT( slotRemoveProperty() ) );
115 
116  connect(tool_, SIGNAL( widgetShown() ), this, SLOT( updateGUI() ) );
117 
118  setNewPropertyModel(-1);
119  }
120 }
121 
122 //-----------------------------------------------------------------------------
123 
124 void PropertyVisPlugin::slotVisualizeProperty( int _id, const QString& _propname )
125 {
126  PropertyModel* model = PropertyModelFactory::Instance().getModel(_id);
127 
128  if (model != 0)
129  {
130  model->gatherProperties();
131  QModelIndex idx = model->indexFromPlainPropName(_propname);
132 
133  if (idx.isValid())
134  {
135  QModelIndexList list;
136  list.append(idx);
137 
138  model->visualize(list);
139 
140 
141  emit updateView();
142  emit updatedObject( _id, UPDATE_COLOR );
143  }
144  }
145 }
146 
147 //-----------------------------------------------------------------------------
148 
149 void PropertyVisPlugin::slotPickModeChanged( const std::string& _mode)
150 {
151  if (propertyModel_ != 0)
152  propertyModel_->pickModeChanged(_mode);
153 }
154 
155 //-----------------------------------------------------------------------------
156 
157 void PropertyVisPlugin::slotAllCleared()
158 {
159  using namespace PluginFunctions;
160 
161  if (propertyModel_ != 0)
162  {
163  QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
164  propertyModel_->clear(selectedIndices);
165  propertyModel_->objectUpdated();
166  emit updateView();
167  }
168 }
169 
170 //-----------------------------------------------------------------------------
171 
172 void PropertyVisPlugin::objectDeleted(int _id)
173 {
174  if( OpenFlipper::Options::gui() )
175  objectListItemModel_.removeObject(_id);
176  PropertyModelFactory::Instance().deleteModel(_id);
177 }
178 
179 //-----------------------------------------------------------------------------
180 
181 void PropertyVisPlugin::slotObjectUpdated( int _identifier, const UpdateType& _type )
182 {
183  if( OpenFlipper::Options::gui() )
184  {
185  if ( tool_->isVisible() )
186  updateGUI();
187  PropertyModel* propertyModel = PropertyModelFactory::Instance().getModel(_identifier);
188  if (propertyModel)
189  {
190  if (_type == UPDATE_ALL)
191  propertyModel->gatherProperties();
192  if (_type == (UPDATE_ALL | UPDATE_GEOMETRY))
193  propertyModel->objectUpdated();
194  }
195  }
196 }
197 
198 void PropertyVisPlugin::updateGUI()
199 {
201 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
202  datatype |= DataType(DATA_POLYHEDRAL_MESH);
203 #endif
204 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
205  datatype |= DataType(DATA_HEXAHEDRAL_MESH);
206 #endif
207 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
208  datatype |= DataType(DATA_TETRAHEDRAL_MESH);
209 #endif
210  objectListItemModel_.refresh(datatype);
211 }
212 
213 //-----------------------------------------------------------------------------
214 
216 {
217  if (propertyModel_ != 0)
218  {
219  QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
220  propertyModel_->updateWidget(selectedIndices);
221  }
222 }
223 
224 //-----------------------------------------------------------------------------
225 
226 
236 {
237  if (propertyModel_)
238  {
239  propertyModel_->hideWidget();
240  disconnect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString)));
241  disconnect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString)));
242  }
243  propertyModel_ = PropertyModelFactory::Instance().getModel(id);
244  if (propertyModel_ != 0)
245  {
246 
247  tool_->propertyName_lv->setModel(propertyModel_);
248  connect(propertyModel_, SIGNAL( modelReset() ), this, SLOT( propertySelectionChanged() ));
249  connect(tool_->propertyName_lv->selectionModel(),
250  SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
251  this,
252  SLOT( propertySelectionChanged() ));
253  QWidget* widget = propertyModel_->getWidget();
254  tool_->propertyWidgets->addWidget(widget);
255  widget->show();
256  propertyModel_->gatherProperties();
257  connect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString)));
258  connect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString)));
259  }
260  else
261  {
262  tool_->propertyName_lv->setModel(0);
263  }
264 }
265 
266 //-----------------------------------------------------------------------------
267 
268 void PropertyVisPlugin::slotMeshChanged(int /*_index*/)
269 {
270  int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
271  setNewPropertyModel(id);
272 }
273 
274 //-----------------------------------------------------------------------------
275 
276 void PropertyVisPlugin::slotVisualize()
277 {
278  using namespace PluginFunctions;
279 
280  // return if nothing is selected
281  if (propertyModel_ == 0) return;
282 
283  int selectedId = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
284  QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
285 
286  // visualize property
287  propertyModel_->visualize(selectedIndices);
288 
289  // emit updates
290  emit updateView();
291 
292  if (selectedId >= 0)
293  {
294  emit updatedObject( selectedId, UPDATE_COLOR );
295  }
296  else
297  {
298  ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
299  while (o_it != objectsEnd())
300  {
301  emit updatedObject( o_it->id(), UPDATE_COLOR );
302  ++o_it;
303  }
304  }
305 }
306 
307 //-----------------------------------------------------------------------------
308 
309 void PropertyVisPlugin::slotMouseEvent( QMouseEvent* _event ) {
310  if (propertyModel_ != 0)
311  propertyModel_->mouseEvent(_event);
312 }
313 
314 //-----------------------------------------------------------------------------
315 
317 {
318  using namespace PluginFunctions;
319 
320  if (propertyModel_ != 0)
321  {
322  QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
323  propertyModel_->duplicateProperty(selectedIndices);
324 
325  emit updateView();
326  int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
327  slotMeshChanged();
328 
329  if (id >= 0)
330  {
331  emit updatedObject( id, UPDATE_ALL );
332  }
333  else
334  {
335  ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
336  while (o_it != objectsEnd())
337  {
338  emit updatedObject( o_it->id(), UPDATE_ALL );
339  ++o_it;
340  }
341  }
342  }
343 }
344 
346 {
347  using namespace PluginFunctions;
348 
349  if (propertyModel_ != 0)
350  {
351  QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
352  propertyModel_->removeProperty(selectedIndices);
353 
354  emit updateView();
355  int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
356 
357  if (id >= 0)
358  {
359  emit updatedObject( id, UPDATE_ALL );
360  }
361  else
362  {
363  ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
364  while (o_it != objectsEnd())
365  {
366  emit updatedObject( o_it->id(), UPDATE_ALL );
367  ++o_it;
368  }
369  }
370  }
371 }
372 
373 #if QT_VERSION < 0x050000
374  Q_EXPORT_PLUGIN2( propertyvisplugin , PropertyVisPlugin );
375 #endif
376 
void setNewPropertyModel(int id)
Exchanges the PropertyModel after the user selected a different object.
Predefined datatypes.
Definition: DataTypes.hh:96
void propertySelectionChanged()
Called when user selects a property.
Logtype
Log types for Message Window.
QModelIndex indexFromPlainPropName(const QString &propName) const
Returns the index of the property with the given name.
#define DATA_POLYHEDRAL_MESH
int id() const
Definition: BaseObject.cc:201
const QStringList ALL_OBJECTS
Iterable object range.
virtual void gatherProperties()=0
Searches for properties and creates PropertyVisualizers.
Update type class.
Definition: UpdateType.hh:70
static T & Instance()
Definition: SingletonT.hh:94
void slotDuplicateProperty()
Duplicates the selected properties.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
#define DATA_HEXAHEDRAL_MESH
virtual void objectUpdated()=0
Revisualizes visualized properties.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
void slotRemoveProperty()
Removes the selected properties.
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList())=0
Visualizes the selected properties.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.