Developer Documentation
Loading...
Searching...
No Matches
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//=============================================================================
45//
46// CLASS PropertyVisPlugin - IMPLEMENTATION
47//
48//=============================================================================
49
50//== INCLUDES =================================================================
51
52#include "PropertyVisPlugin.hh"
53
54#include "Models/PropertyModelFactory.hh"
55#include "Models/SingleObjectPropertyModel.hh"
56
57#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
59#endif
60#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
62#endif
63#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
65#endif
66
67//== IMPLEMENTATION ==========================================================
68
69#define PROP_VIS "PropertyVisualization"
70
71#include <QStringListModel>
72
73PropertyVisPlugin::PropertyVisPlugin() :
74tool_(nullptr),
75toolIcon_(nullptr),
76propertyModel_(nullptr)
77{
78}
79
80PropertyVisPlugin::~PropertyVisPlugin()
81{
82 delete toolIcon_;
83}
84
85void PropertyVisPlugin::initializePlugin()
86{
87 if ( OpenFlipper::Options::gui() ) {
88 tool_ = new PropertyVisToolbar();
89
90 QSize size(300,300);
91 tool_->resize(size);
92
93 tool_->meshNames->setModel(&objectListItemModel_);
94
95 emit addHiddenPickMode( PROP_VIS );
96
97 toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"PropertyVisIcon.png");
98
99 emit addToolbox( tr("Property Visualization") , tool_, toolIcon_ );
100 }
101}
102
103//-----------------------------------------------------------------------------
104
105void PropertyVisPlugin::pluginsInitialized()
106{
107 if ( OpenFlipper::Options::gui() ) {
108
109 // connect toolbox elements
110 connect(tool_->meshNames, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotMeshChanged(int) ) );
111
112 connect(tool_->visualizeButton, SIGNAL( clicked() ), this, SLOT( slotVisualize() ) );
113 connect(tool_->clearButton, SIGNAL( clicked() ), this, SLOT( slotAllCleared() ) );
114
115 connect(tool_->refresh_property_names_tb, SIGNAL( clicked() ), this, SLOT( slotMeshChanged() ) );
116 connect(tool_->duplicate_property_tb, SIGNAL( clicked() ), this, SLOT( slotDuplicateProperty() ) );
117 connect(tool_->remove_property_tb, SIGNAL( clicked() ), this, SLOT( slotRemoveProperty() ) );
118
119 connect(tool_, SIGNAL( widgetShown() ), this, SLOT( updateGUI() ) );
120
122 }
123}
124
125//-----------------------------------------------------------------------------
126
127void PropertyVisPlugin::slotVisualizeProperty( int _id, const QString& _propname )
128{
129 PropertyModel* model = PropertyModelFactory::Instance().getModel(_id);
130
131 if (model != 0)
132 {
133 model->gatherProperties();
134 QModelIndex idx = model->indexFromPlainPropName(_propname);
135
136 if (idx.isValid())
137 {
138 QModelIndexList list;
139 list.append(idx);
140
141 model->visualize(list);
142
143
144 emit updateView();
145 emit updatedObject( _id, UPDATE_COLOR );
146 }
147 }
148}
149
150void PropertyVisPlugin::slotClear(int _id, const QString &_propname)
151{
152 PropertyModel* model = PropertyModelFactory::Instance().getModel(_id);
153
154 if (model != 0)
155 {
156 model->gatherProperties();
157 QModelIndex idx = model->indexFromPlainPropName(_propname);
158
159 if (idx.isValid())
160 {
161 QModelIndexList list;
162 list.append(idx);
163
164 model->clear(list);
165
166 emit updateView();
167 emit updatedObject( _id, UPDATE_COLOR );
168 }
169 }
170}
171
172#if QT_VERSION_MAJOR < 6
173QScriptValue PropertyVisPlugin::getPropertyVisualizer(int _id, const QString &_propname)
174{
175 PropertyModel* model = PropertyModelFactory::Instance().getModel(_id);
176
177 if (model == nullptr) { return QScriptValue::SpecialValue::NullValue; }
178
179 model->gatherProperties();
180 QModelIndex idx = model->indexFromPlainPropName(_propname);
181 if (!idx.isValid()) { return QScriptValue::SpecialValue::NullValue; }
182
183 QScriptEngine *engine;
184 emit getScriptingEngine (engine);
185 if (engine == nullptr) { return QScriptValue::SpecialValue::NullValue; }
186
187 QScriptContext *ctx = engine->currentContext();
188 if (ctx == nullptr) { return QScriptValue::SpecialValue::NullValue; }
189
190 auto sopm = dynamic_cast<SingleObjectPropertyModel*>(model);
191 if (!sopm) { return QScriptValue::SpecialValue::NullValue; }
192
193 return sopm->getScriptObject(idx, ctx);
194}
195#endif
196
197//-----------------------------------------------------------------------------
198
199void PropertyVisPlugin::slotPickModeChanged( const std::string& _mode)
200{
201 if (propertyModel_)
202 propertyModel_->pickModeChanged(_mode);
203}
204
205//-----------------------------------------------------------------------------
206
207void PropertyVisPlugin::slotAllCleared()
208{
209 using namespace PluginFunctions;
210
211 if (propertyModel_)
212 {
213 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
214 propertyModel_->clear(selectedIndices);
215 propertyModel_->objectUpdated();
216 emit updateView();
217 }
218}
219
220//-----------------------------------------------------------------------------
221
222void PropertyVisPlugin::objectDeleted(int _id)
223{
224 if( OpenFlipper::Options::gui() )
225 objectListItemModel_.removeObject(_id);
226 PropertyModelFactory::Instance().deleteModel(_id);
227}
228
229//-----------------------------------------------------------------------------
230
231void PropertyVisPlugin::slotObjectUpdated( int _identifier, const UpdateType& _type )
232{
233 if( OpenFlipper::Options::gui() )
234 {
235 if ( tool_->isVisible() )
236 updateGUI();
237 PropertyModel* propertyModel = PropertyModelFactory::Instance().getModel(_identifier);
238 if (propertyModel)
239 {
240 if (_type == UPDATE_ALL)
241 propertyModel->gatherProperties();
242 if (_type == (UPDATE_ALL | UPDATE_GEOMETRY))
243 propertyModel->objectUpdated();
244 }
245 }
246}
247
248void PropertyVisPlugin::slotObjectPropertiesChanged(int _identifier)
249{
250 // We get this signal when properties are renamed
251 if( OpenFlipper::Options::gui() && tool_->isVisible() )
252 {
253 updateGUI();
254 }
255}
256
257void PropertyVisPlugin::updateGUI()
258{
260#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
261 datatype |= DataType(DATA_POLYHEDRAL_MESH);
262#endif
263#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
264 datatype |= DataType(DATA_HEXAHEDRAL_MESH);
265#endif
266#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
267 datatype |= DataType(DATA_TETRAHEDRAL_MESH);
268#endif
269 objectListItemModel_.refresh(datatype);
270}
271
272//-----------------------------------------------------------------------------
273
275{
276 if (propertyModel_)
277 {
278 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
279 propertyModel_->updateWidget(selectedIndices);
280 }
281}
282
283//-----------------------------------------------------------------------------
284
285
295{
296 if (propertyModel_)
297 {
298 propertyModel_->hideWidget();
299 disconnect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString)));
300 disconnect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString)));
301 }
302 propertyModel_ = PropertyModelFactory::Instance().getModel(id);
303 if (propertyModel_)
304 {
305
306 tool_->propertyName_lv->setModel(propertyModel_);
307 connect(propertyModel_, SIGNAL( modelReset() ), this, SLOT( propertySelectionChanged() ));
308 connect(tool_->propertyName_lv->selectionModel(),
309 SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
310 this,
311 SLOT( propertySelectionChanged() ));
312 QWidget* widget = propertyModel_->getWidget();
313 tool_->propertyWidgets->addWidget(widget);
314 widget->show();
315 propertyModel_->gatherProperties();
316 connect(propertyModel_, SIGNAL(log(Logtype,QString)), this, SLOT(slotLog(Logtype,QString)));
317 connect(propertyModel_, SIGNAL(log(QString)), this, SLOT(slotLog(QString)));
318 }
319 else
320 {
321 tool_->propertyName_lv->setModel(0);
322 }
323}
324
325//-----------------------------------------------------------------------------
326
327void PropertyVisPlugin::slotMeshChanged(int /*_index*/)
328{
329 int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
331}
332
333//-----------------------------------------------------------------------------
334
335void PropertyVisPlugin::slotVisualize()
336{
337 using namespace PluginFunctions;
338
339 // return if nothing is selected
340 if (propertyModel_ == nullptr) return;
341
342 int selectedId = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
343 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
344
345 // visualize property
346 propertyModel_->visualize(selectedIndices);
347
348 // emit updates
349 emit updateView();
350
351 if (selectedId >= 0)
352 {
353 emit updatedObject( selectedId, UPDATE_COLOR );
354 }
355 else
356 {
357 ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
358 while (o_it != objectsEnd())
359 {
360 emit updatedObject( o_it->id(), UPDATE_COLOR );
361 ++o_it;
362 }
363 }
364}
365
366//-----------------------------------------------------------------------------
367
368void PropertyVisPlugin::slotMouseEvent( QMouseEvent* _event ) {
369 if (propertyModel_)
370 propertyModel_->mouseEvent(_event);
371}
372
373//-----------------------------------------------------------------------------
374
376{
377 using namespace PluginFunctions;
378
379 if (propertyModel_)
380 {
381 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
382 propertyModel_->duplicateProperty(selectedIndices);
383
384 emit updateView();
385 int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
386 slotMeshChanged();
387
388 if (id >= 0)
389 {
390 emit updatedObject( id, UPDATE_ALL );
391 }
392 else
393 {
394 ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
395 while (o_it != objectsEnd())
396 {
397 emit updatedObject( o_it->id(), UPDATE_ALL );
398 ++o_it;
399 }
400 }
401 }
402}
403
405{
406 using namespace PluginFunctions;
407
408 if (propertyModel_)
409 {
410 QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes();
411 propertyModel_->removeProperty(selectedIndices);
412
413 emit updateView();
414 int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt();
415
416 if (id >= 0)
417 {
418 emit updatedObject( id, UPDATE_ALL );
419 }
420 else
421 {
422 ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
423 while (o_it != objectsEnd())
424 {
425 emit updatedObject( o_it->id(), UPDATE_ALL );
426 ++o_it;
427 }
428 }
429 }
430}
431
432
Logtype
Log types for Message Window.
#define DATA_HEXAHEDRAL_MESH
#define DATA_POLYHEDRAL_MESH
#define DATA_TETRAHEDRAL_MESH
#define DATA_POLY_MESH
Definition PolyMesh.hh:59
#define DATA_TRIANGLE_MESH
int id() const
Predefined datatypes.
Definition DataTypes.hh:83
static T & Instance()
Definition SingletonT.hh:86
virtual void updateWidget(const QModelIndexList &selectedIndices)=0
Updates the widget.
QModelIndex indexFromPlainPropName(const QString &propName) const
Returns the index of the property with the given name.
virtual void objectUpdated()=0
Revisualizes visualized properties.
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList())=0
Visualizes the selected properties.
virtual QWidget * getWidget()=0
Returns the widget.
virtual void removeProperty(QModelIndexList selectedIndices)=0
Removes the selected properties.
virtual void hideWidget()=0
Hides the widget.
virtual void gatherProperties()=0
Searches for properties and creates PropertyVisualizers.
virtual void clear(QModelIndexList selectedIndices)=0
Clears the selected property visualization.
virtual void duplicateProperty(QModelIndexList selectedIndices)=0
Duplicates the selected properties.
void propertySelectionChanged()
Called when user selects a property.
void slotClear(int _id, const QString &_propname)
void setNewPropertyModel(int id)
Exchanges the PropertyModel after the user selected a different object.
void slotDuplicateProperty()
Duplicates the selected properties.
void slotRemoveProperty()
Removes the selected properties.
void slotLog(Logtype _type, QString _message)
Receives log messages from PropertyModels and emits them.
void slotVisualizeProperty(int _id, const QString &_propname)
This class manages the visualizers for a single object.
virtual QScriptValue getScriptObject(const QModelIndex index, QScriptContext *ctx)
Returns a qscript object that can be used to access visualisation parameters.
Update type class.
Definition UpdateType.hh:59
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1024))
Colors have changed.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.