Developer Documentation
Loading...
Searching...
No Matches
objectPickDialog.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//== INCLUDES =================================================================
45#include <QHBoxLayout>
46#include <QPushButton>
47#include <QTreeView>
48#include <QMouseEvent>
49
51#include <OpenFlipper/widgets/glWidget/simpleViewer.hh>
52#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
53
54#include "objectPickDialog.hh"
55#include "TreeModelObjectSelection.hh"
56
57//== NAMESPACES ===============================================================
58
59//=============================================================================
60//
61// CLASS ObjectPickDialog - IMPLEMENTATION
62//
63//=============================================================================
64
66ObjectPickDialog::ObjectPickDialog(QStringList _flags, QStringList _types, bool _withGroups) :
67 QDialog (),
68 selectedId_(0)
69{
70 QHBoxLayout *hL = new QHBoxLayout;
71 QHBoxLayout *bL = new QHBoxLayout;
72 QVBoxLayout *vL = new QVBoxLayout;
73
74 model_ = new TreeModelObjectSelection ();
75
76 treeView_ = new QTreeView;
77 treeView_->setModel (model_);
78 treeView_->resizeColumnToContents (0);
79 treeView_->setSelectionMode (QAbstractItemView::SingleSelection);
80 treeView_->setSelectionBehavior (QAbstractItemView::SelectRows);
81
82 viewer_ = new SimpleViewer ();
83 viewer_->properties ().objectMarker (&marker_);
84
85 okButton_ = new QPushButton (tr("OK"));
86 cancelButton_ = new QPushButton (tr("Cancel"));
87
88 connect (okButton_, SIGNAL (pressed()), this, SLOT (accept()));
89 connect (cancelButton_, SIGNAL (pressed()), this, SLOT (reject()));
90
91 hL->addWidget (viewer_);
92 hL->setStretchFactor (viewer_, 1);
93 hL->addWidget (treeView_);
94
95 bL->addStretch (1);
96 bL->addWidget (okButton_);
97 bL->addWidget (cancelButton_);
98
99 vL->addLayout(hL);
100 vL->addLayout(bL);
101
102 setLayout (vL);
103
104 resize (700, 400);
105
106 setWindowTitle(tr("Click on object or select from list..."));
107
108 connect (treeView_, SIGNAL (activated( const QModelIndex& )),
109 this, SLOT (activated(const QModelIndex&)));
110 connect (viewer_->viewer(), SIGNAL (signalMouseEventClick(QMouseEvent*, bool)),
111 this, SLOT (slotMouseEventClick(QMouseEvent*, bool)));
112
114
115
116 bool ok = true;
117
118 if (!_flags.empty ())
119 {
120 bool found = false;
121 foreach (QString flag, _flags)
122 if (o_it->flag (flag))
123 {
124 found = true;
125 break;
126 }
127
128 if (!found)
129 ok = false;
130 }
131
132 if (!_types.empty ())
133 {
134 if (!_types.contains (typeName (o_it->dataType())))
135 ok = false;
136 }
137
138 if (o_it->isGroup() && !_withGroups)
139 continue;
140
141 if (ok)
142 {
143 if (!_withGroups)
145 else
146 model_->objectAdded (o_it);
147 }
148 }
149}
150
151//------------------------------------------------------------------------------
152
154ObjectPickDialog::~ ObjectPickDialog()
155{
157 o_it->setFlag("vsi_objectId_selected", false);
158 }
159
160 delete model_;
161}
162
163//------------------------------------------------------------------------------
164
165void ObjectPickDialog::activated(const QModelIndex & _index)
166{
167 if (_index.isValid()) {
168
169 TreeItemObjectSelection *item = static_cast<TreeItemObjectSelection*>(_index.internalPointer());
170 if (item)
171 {
172 selectedId (item->id());
173 }
174 }
175}
176
177//------------------------------------------------------------------------------
178
179void ObjectPickDialog::slotMouseEventClick(QMouseEvent * _event, bool /*_double*/)
180{
181 size_t nodeIdx, targetIdx;
182
183
184 if (viewer_->viewer()->pick(ACG::SceneGraph::PICK_ANYTHING, _event->pos(), nodeIdx, targetIdx))
185 {
186 BaseObjectData *obj = 0;
187 if (PluginFunctions::getPickedObject (nodeIdx, obj))
188 {
189 if (!obj->flag ("vsi_objectId_disabled"))
190 {
191 selectedId (obj->id());
192 }
193 }
194 }
195}
196
197//------------------------------------------------------------------------------
198
200{
201 return selectedId_;
202}
203
204//------------------------------------------------------------------------------
205
206void ObjectPickDialog::selectedId(unsigned int _id)
207{
208 BaseObject* obj = 0;
209
210 if (PluginFunctions::getObject(_id, obj))
211 {
212 BaseObject* obj2 = 0;
213
214 if (selectedId_ != _id && PluginFunctions::getObject(selectedId_, obj2))
215 {
216 obj2->setFlag ("vsi_objectId_selected", false);
217 if (obj2->isGroup())
218 setForGroup (obj2, "vsi_objectId_selected", false);
219 }
220 obj->setFlag ("vsi_objectId_selected", true);
221 if (obj->isGroup())
222 setForGroup (obj, "vsi_objectId_selected", true);
223
224 selectedId_ = _id;
225 viewer_->viewer()->updateGL ();
226 treeView_->setCurrentIndex (model_->getModelIndex(_id, 0));
227 }
228}
229
230//------------------------------------------------------------------------------
231
232void ObjectPickDialog::setForGroup(BaseObject *_obj, QString _flag, bool _enabled)
233{
235 if (o_it->id () == _obj->id ())
236 continue;
237 if (o_it->isInGroup (_obj->id ()))
238 {
239 o_it->setFlag(_flag, _enabled);
240 if (o_it->isGroup())
241 setForGroup (o_it, _flag, _enabled);
242 }
243 }
244}
245
246//------------------------------------------------------------------------------
247
248
249
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
Definition Types.cc:154
void setFlag(QString _flag, bool _set)
bool flag(QString _flag)
bool isGroup() const
Check if object is a group.
int id() const
ObjectPickDialog(QStringList _flags, QStringList _types, bool _withGroups)
Constructor.
unsigned int selectedId()
Current selected object.
Core Data Iterator used to iterate over all objects (Including groups)
glViewer * viewer()
Viewer.
Viewer::ViewerProperties & properties()
Viewer properties.
QModelIndex getModelIndex(TreeItemObjectSelection *_object, int _column)
Return the ModelIndex corresponding to a given TreeItemObjectSelection and Column.
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
void objectMarker(ViewObjectMarker *_marker)
set object marker for viewer
bool pick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
virtual void updateGL()
Redraw scene. Triggers paint event for updating the view (cf. drawNow()).
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
Definition PickTarget.hh:84
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
BaseObject *& objectRoot()
Get the root of the object structure.