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