Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
63 #endif
64 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
65 #endif
66
67 //== IMPLEMENTATION ==========================================================
68
69 #define PROP_VIS "PropertyVisualization"
70
71 PropertyVisPlugin::PropertyVisPlugin() :
72 tool_(0),
73 propertyModel_(0)
74 {
75 }
76
77 void PropertyVisPlugin::initializePlugin()
78 {
79 if ( OpenFlipper::Options::gui() ) {
80 tool_ = new PropertyVisToolbar();
81
82 QSize size(300,300);
83 tool_->resize(size);
84
85 tool_->meshNames->setModel(&objectListItemModel_);
86
87 emit addHiddenPickMode( PROP_VIS );
88
89 QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"PropertyVisIcon.png");
90
91 emit addToolbox( tr("Property Visualization") , tool_, toolIcon );
92 }
93 }
94
95 //-----------------------------------------------------------------------------
96
97 void PropertyVisPlugin::pluginsInitialized()
98 {
99 if ( OpenFlipper::Options::gui() ) {
100
101 // connect toolbox elements
102 connect(tool_->meshNames, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotMeshChanged(int) ) );
103
104 connect(tool_->visualizeButton, SIGNAL( clicked() ), this, SLOT( slotVisualize() ) );
105 connect(tool_->clearButton, SIGNAL( clicked() ), this, SLOT( slotAllCleared() ) );
106
107 connect(tool_->refresh_property_names_tb, SIGNAL( clicked() ), this, SLOT( slotMeshChanged() ) );
108 connect(tool_->duplicate_property_tb, SIGNAL( clicked() ), this, SLOT( slotDuplicateProperty() ) );
109 connect(tool_->remove_property_tb, SIGNAL( clicked() ), this, SLOT( slotRemoveProperty() ) );
110
111 connect(tool_, SIGNAL( widgetShown() ), this, SLOT( updateGUI() ) );
112
113 setNewPropertyModel(-1);
114 }
115 }
116
117 //-----------------------------------------------------------------------------
118
119 void PropertyVisPlugin::slotVisualizeProperty( int _id, const QString& _propname )
120 {
121 PropertyModel* model = PropertyModelFactory::Instance().getModel(_id);
122
123 if (model != 0)
124 {
125 model->gatherProperties();
126 QModelIndex idx = model->indexFromPlainPropName(_propname);
127
128 if (idx.isValid())
129 {
130 QModelIndexList list;
131 list.append(idx);
132
133 model->visualize(list);
134
135
136 emit updateView();
137 emit updatedObject( _id, UPDATE_COLOR );
138 }
139 }
140 }
141
142 //-----------------------------------------------------------------------------
143
144 void PropertyVisPlugin::slotPickModeChanged( const std::string& _mode)
145 {
146 if (propertyModel_ != 0)
147 propertyModel_->pickModeChanged(_mode);
148 }
149
150 //-----------------------------------------------------------------------------
151
152 void PropertyVisPlugin::slotAllCleared()
153 {
154 using namespace PluginFunctions;
155
156 if (propertyModel_ != 0)
157 {
158 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
159 propertyModel_->clear(selectedIndices);
160 propertyModel_->objectUpdated();
161 emit updateView();
162 }
163 }
164
165 //-----------------------------------------------------------------------------
166
167 void PropertyVisPlugin::objectDeleted(int _id)
168 {
169 if( OpenFlipper::Options::gui() )
170 objectListItemModel_.removeObject(_id);
171 PropertyModelFactory::Instance().deleteModel(_id);
172 }
173
174 //-----------------------------------------------------------------------------
175
176 void PropertyVisPlugin::slotObjectUpdated( int _identifier, const UpdateType& _type )
177 {
178 if( OpenFlipper::Options::gui() )
179 {
180 if ( tool_->isVisible() )
181 updateGUI();
182 PropertyModel* propertyModel = PropertyModelFactory::Instance().getModel(_identifier);
183 if (propertyModel)
184 {
185 if (_type == UPDATE_ALL)
186 propertyModel->gatherProperties();
187 if (_type == (UPDATE_ALL | UPDATE_GEOMETRY))
188 propertyModel->objectUpdated();
189 }
190 }
191 }
192
193 void PropertyVisPlugin::updateGUI()
194 {
195 DataType datatype = DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH);
196 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
197 datatype |= DataType(DATA_POLYHEDRAL_MESH);
198 #endif
199 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
200 datatype |= DataType(DATA_HEXAHEDRAL_MESH);
201 #endif
202 objectListItemModel_.refresh(datatype);
203 }
204
205 //-----------------------------------------------------------------------------
206
207 void PropertyVisPlugin::propertySelectionChanged()
208 {
209 if (propertyModel_ != 0)
210 {
211 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
212 propertyModel_->updateWidget(selectedIndices);
213 }
214 }
215
216 //-----------------------------------------------------------------------------
217
218
227 void PropertyVisPlugin::setNewPropertyModel(int id)
228 {
229 if (propertyModel_)
230 {
231 propertyModel_->hideWidget();
232 disconnect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString)));
233 disconnect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString)));
234 }
235 propertyModel_ = PropertyModelFactory::Instance().getModel(id);
236 if (propertyModel_ != 0)
237 {
238
239 tool_->propertyName_lv->setModel(propertyModel_);
240 connect(propertyModel_, SIGNAL( modelReset() ), this, SLOT( propertySelectionChanged() ));
241 connect(tool_->propertyName_lv->selectionModel(),
242 SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
243 this,
244 SLOT( propertySelectionChanged() ));
245 QWidget* widget = propertyModel_->getWidget();
246 tool_->propertyWidgets->addWidget(widget);
247 widget->show();
248 propertyModel_->gatherProperties();
249 connect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString)));
250 connect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString)));
251 }
252 else
253 {
254 tool_->propertyName_lv->setModel(0);
255 }
256 }
257
258 //-----------------------------------------------------------------------------
259
260 void PropertyVisPlugin::slotMeshChanged(int /*_index*/)
261 {
262 int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
263 setNewPropertyModel(id);
264 }
265
266 //-----------------------------------------------------------------------------
267
268 void PropertyVisPlugin::slotVisualize()
269 {
270 using namespace PluginFunctions;
271
272 // return if nothing is selected
273 if (propertyModel_ == 0) return;
274
275 int selectedId = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
276 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
277
278 // visualize property
279 propertyModel_->visualize(selectedIndices);
280
281 // emit updates
282 emit updateView();
283
284 if (selectedId >= 0)
285 {
286 emit updatedObject( selectedId, UPDATE_COLOR );
287 }
288 else
289 {
290 ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
291 while (o_it != objectsEnd())
292 {
293 emit updatedObject( o_it->id(), UPDATE_COLOR );
294 ++o_it;
295 }
296 }
297 }
298
299 //-----------------------------------------------------------------------------
300
301 void PropertyVisPlugin::slotMouseEvent( QMouseEvent* _event ) {
302 if (propertyModel_ != 0)
303 propertyModel_->mouseEvent(_event);
304 }
305
306 //-----------------------------------------------------------------------------
307
308 void PropertyVisPlugin::slotDuplicateProperty()
309 {
310 using namespace PluginFunctions;
311
312 if (propertyModel_ != 0)
313 {
314 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
315 propertyModel_->duplicateProperty(selectedIndices);
316
317 emit updateView();
318 int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
319 slotMeshChanged();
320
321 if (id >= 0)
322 {
323 emit updatedObject( id, UPDATE_ALL );
324 }
325 else
326 {
327 ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
328 while (o_it != objectsEnd())
329 {
330 emit updatedObject( o_it->id(), UPDATE_ALL );
331 ++o_it;
332 }
333 }
334 }
335 }
336
337 void PropertyVisPlugin::slotRemoveProperty()
338 {
339 using namespace PluginFunctions;
340
341 if (propertyModel_ != 0)
342 {
343 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
344 propertyModel_->removeProperty(selectedIndices);
345
346 emit updateView();
347 int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
348
349 if (id >= 0)
350 {
351 emit updatedObject( id, UPDATE_ALL );
352 }
353 else
354 {
355 ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
356 while (o_it != objectsEnd())
357 {
358 emit updatedObject( o_it->id(), UPDATE_ALL );
359 ++o_it;
360 }
361 }
362 }
363 }
364
365 #if QT_VERSION < 0x050000
366 Q_EXPORT_PLUGIN2( propertyvisplugin , PropertyVisPlugin );
367 #endif
368
PluginFunctions::ALL_OBJECTS
const QStringList ALL_OBJECTS
Iterable object range.
Definition: PluginFunctions.hh:441
UPDATE_GEOMETRY
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
PropertyVisPlugin::slotDuplicateProperty
void slotDuplicateProperty()
Duplicates the selected properties.
Definition: PropertyVisPlugin.cc:308
PropertyModel
Definition: PropertyModel.hh:59
Logtype
Logtype
Log types for Message Window.
Definition: LoggingInterface.hh:103
PluginFunctions
Definition: PluginFunctionsBSplineCurve.cc:69
PropertyVisPlugin::slotRemoveProperty
void slotRemoveProperty()
Removes the selected properties.
Definition: PropertyVisPlugin.cc:337
PropertyVisPlugin::setNewPropertyModel
void setNewPropertyModel(int id)
Exchanges the PropertyModel after the user selected a different object.
Definition: PropertyVisPlugin.cc:227
UpdateType
Update type class.
Definition: UpdateType.hh:70
DATA_POLYHEDRAL_MESH
#define DATA_POLYHEDRAL_MESH
Definition: PolyhedralMesh.hh:63
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PropertyVisToolbar
Definition: PropertyVisToolbar.hh:59
PropertyModel::getWidget
virtual QWidget * getWidget()=0
Returns the widget.
PropertyModel::indexFromPlainPropName
QModelIndex indexFromPlainPropName(const QString &propName) const
Returns the index of the property with the given name.
Definition: PropertyModel.cc:63
PropertyModel::gatherProperties
virtual void gatherProperties()=0
Searches for properties and creates PropertyVisualizers.
PluginFunctions::ObjectIterator
Core Data Iterator.
Definition: PluginFunctions.hh:452
PluginFunctions::objectsEnd
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsIterator.cc:187
DATA_POLY_MESH
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
PropertyModel::objectUpdated
virtual void objectUpdated()=0
Revisualizes visualized properties.
PropertyVisPlugin::slotLog
void slotLog(Logtype _type, QString _message)
Receives log messages from PropertyModels and emits them.
Definition: PropertyVisPlugin.hh:154
PropertyModel::visualize
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList())=0
Visualizes the selected properties.
PropertyVisPlugin
Definition: PropertyVisPlugin.hh:87
OpenMesh::SingletonT::Instance
static T & Instance()
Definition: SingletonT.hh:94
PropertyModel::hideWidget
virtual void hideWidget()=0
Hides the widget.
DATA_HEXAHEDRAL_MESH
#define DATA_HEXAHEDRAL_MESH
Definition: HexahedralMesh.hh:63
UPDATE_COLOR
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
DataType
Predefined datatypes.
Definition: DataTypes.hh:96
DATA_TRIANGLE_MESH
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
PropertyModel::updateWidget
virtual void updateWidget(const QModelIndexList &selectedIndices)=0
Updates the widget.
BaseObject::id
int id() const
Definition: BaseObject.cc:201
PropertyVisPlugin::propertySelectionChanged
void propertySelectionChanged()
Called when user selects a property.
Definition: PropertyVisPlugin.cc:207