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
Popup.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
53 #include "DataControlPlugin.hh"
54
55 #include <ACG/QtWidgets/QtMaterialDialog.hh>
56
57 #include "Menu.hh"
58
59 #include <ObjectTypes/Light/LightWidget.hh>
60
61
62 //******************************************************************************
63
67 void DataControlPlugin::slotPopupRemove ( ) {
68
69 QItemSelectionModel* selection = view_->selectionModel();
70
71 if (selection == 0) return;
72
73 // Get all selected rows
74 QModelIndexList indexList = selection->selectedRows();
75
76
77 QMessageBox msgBox;
78 msgBox.setText(tr("Do you really want to remove the selected objects?"));
79 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
80 msgBox.setDefaultButton(QMessageBox::Yes);
81
82 QString text;
83
84 for ( int i = 0 ; i < indexList.size() ; ++i)
85 text += model_->itemName( indexList[i] ) + "\n";
86
87 msgBox.setDetailedText(text);
88
89 if ( msgBox.exec() == QMessageBox::No)
90 return;
91
92 for ( int i = 0 ; i < indexList.size() ; ++i) {
93
94 int id = model_->itemId( indexList[i] );
95
96
97 if ( id != -1 )
98 emit deleteObject( id );
99 }
100
101 emit updateView();
102 }
103
104
105 //******************************************************************************
106
110 void DataControlPlugin::slotUngroup ( ) {
111 QItemSelectionModel* selection = view_->selectionModel();
112
113 // Get all selected rows
114 QModelIndexList indexList = selection->selectedRows ( 0 );
115
116 //get the object
117 int id = model_->itemId( indexList[0] );
118 unGroupObject(id);
119 }
120
121
122 //******************************************************************************
123
127 void DataControlPlugin::slotCopy() {
128 QItemSelectionModel* selection = view_->selectionModel();
129
130 if (selection == 0) return;
131
132 // Get all selected rows
133 QModelIndexList indexList = selection->selectedRows();
134
135 for ( int i = 0 ; i < indexList.size() ; ++i) {
136
137 int id = model_->itemId( indexList[i] );
138
139 if ( id > 0){
140
141 int newObject;
142
143 emit copyObject( id, newObject );
144 }
145
146 }
147
148 emit updateView();
149 }
150
151
152 //******************************************************************************
153
157 void DataControlPlugin::slotGroup() {
158
159 QItemSelectionModel* selection = view_->selectionModel();
160
161 // Get all selected rows
162 QModelIndexList indexList = selection->selectedRows ( 0 );
163
164
165 //get object ids
166 IdList ids;
167 for (int i = 0; i < indexList.size(); ++i)
168 ids.push_back( model_->itemId(indexList[i]) );
169
170 //group all objects
171 groupObjects(ids);
172 }
173
174
175 //******************************************************************************
176
181 void DataControlPlugin::slotCustomContextMenuRequested ( const QPoint & _pos ) {
182 popupIndex_ = view_->indexAt(_pos);
183
184 if (!popupIndex_.isValid())
185 return;
186
187 TreeItem* item = model_->getItem(popupIndex_);
188
189
190 QItemSelectionModel* selection = view_->selectionModel();
191
192 // Get all selected rows
193 QModelIndexList indexList = selection->selectedRows ( 0 );
194 int selectedRows = indexList.size();
195
196 Menu menu(0);
197 QAction* action;
198 QIcon icon;
199 if ( selectedRows > 1 ) {
200 action = menu.addAction("Copy",this,SLOT ( slotCopy() ));
201 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-copy.png");
202 action->setIcon(icon);
203 menu.addAction(tr("Group"),this,SLOT ( slotGroup() ));
204 menu.addSeparator();
205 menu.addAction(tr("Remove"),this,SLOT ( slotPopupRemove() ));
206 }else
207 // check if the item is a group item
208 if ( item->isGroup() ) {
209 action = menu.addAction(tr("Zoom to objects"),this,SLOT ( slotZoomTo() ));
210 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"zoom-in.png");
211 action->setIcon(icon);
212 menu.addAction(tr("Ungroup"),this,SLOT ( slotUngroup() ));
213 menu.addSeparator();
214 action = menu.addAction(tr("Rename"),this,SLOT ( slotRename() ));
215 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-rename.png");
216 action->setIcon(icon);
217 menu.addSeparator();
218 action = menu.addAction(tr("Remove"),this,SLOT ( slotPopupRemove() ));
219 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-delete-item.png");
220 action->setIcon(icon);
221 } else {
222
223 //show object name and id in first entry of the menu
224 int id = model_->itemId( indexList[0] );
225 BaseObject* item = 0;
226 if ( id != -1 && PluginFunctions::getObject(id,item) ) {
227 QAction* header = menu.addAction(tr("Object ")+QString::number(id)+": "+item->name());
228 header->setIcon( typeIcon(item->dataType()) );
229 }
230
231 menu.addSeparator();
232
233 if(item->dataType() == DATA_LIGHT) {
234 action = menu.addAction(tr("Copy"),this,SLOT ( slotCopy() ));
235 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-copy.png");
236 action->setIcon(icon);
237 action = menu.addAction(tr("Rename"),this,SLOT ( slotRename() ));
238 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-rename.png");
239 action->setIcon(icon);
240 action = menu.addAction(tr("Remove"),this,SLOT ( slotPopupRemove() ));
241 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-delete-item.png");
242 action->setIcon(icon);
243 menu.addSeparator();
244
245 LightObject* light = 0;
246 if ( item->id() != -1 && PluginFunctions::getObject( item->id(), light ) ) {
247 if (light != 0 && !light->lightSource()->enabled()) {
248
249 action = menu.addAction(tr("Switch On"),this,SLOT ( slotSwitchLight() ));
250 icon = typeIcon(DATA_LIGHT);
251 }
252 }
253 if (light == 0 || light->lightSource()->enabled())
254 {
255 action = menu.addAction(tr("Switch Off"),this,SLOT ( slotSwitchLight() ));
256 icon = QIcon (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"LightOff.png");
257 }
258 action->setIcon(icon);
259
260 action = menu.addAction(tr("Edit Light"),this,SLOT ( slotEditLight() ));
261 icon = typeIcon(DATA_LIGHT);
262 action->setIcon(icon);
263
264 } else {
265 action = menu.addAction(tr("Zoom to object"),this,SLOT ( slotZoomTo() ));
266 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"zoom-in.png");
267 action->setIcon(icon);
268
269 action = menu.addAction(tr("Copy"),this,SLOT ( slotCopy() ));
270 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-copy.png");
271 action->setIcon(icon);
272
273 action = menu.addAction(tr("Rename"),this,SLOT ( slotRename() ));
274 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-rename.png");
275 action->setIcon(icon);
276
277 action = menu.addAction(tr("Material Properties"),this,SLOT ( slotMaterialProperties() ));
278 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-material.png");
279 action->setIcon(icon);
280
281 action = menu.addAction(tr("Copy Material Properties to Targeted Objects"), this, SLOT ( slotCopyMaterialToTargeted() ));
282 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-copyToTargets-material.png");
283 action->setIcon(icon);
284
285 action = menu.addAction(tr("Copy Material Properties to Clipboard"), this, SLOT ( slotCopyMaterialToClipboard() ));
286 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-copy-material.png");
287 action->setIcon(icon);
288
289 action = menu.addAction(tr("Paste Material Properties from Clipboard"), this, SLOT ( slotPasteMaterialFromClipboard() ));
290 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-paste-material.png");
291 action->setIcon(icon);
292
293 menu.addAction(tr("Group"),this,SLOT ( slotGroup() ));
294
295 menu.addSeparator();
296 action = menu.addAction(tr("Remove"),this,SLOT ( slotPopupRemove() ));
297 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-delete-item.png");
298 action->setIcon(icon);
299 }
300 }
301
302
303
304 menu.exec(view_->mapToGlobal( _pos) );
305
306 }
307
308
309 //******************************************************************************
310
315 void DataControlPlugin::slotHeaderCustomContextMenuRequested ( const QPoint & _pos ) {
316
317 headerPopupType_ = viewHeader_->logicalIndexAt( _pos );
318
319 QMenu menu(0);
320
321 QIcon icon;
322
323 //get all used types
324 QVector<DataType> types;
325
326 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
327 o_it != PluginFunctions::objectsEnd(); ++o_it)
328 if ( !types.contains( o_it->dataType() ) )
329 types.push_back( o_it->dataType() );
330
331 QAction* action;
332
333 switch (headerPopupType_) {
334 // case 0 :
335 // std::cerr << "0";
336 // break;
337 //Show / Hide
338 case 1 :
339 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
340 action = menu.addAction(icon,tr("Show all"),this,SLOT ( showAll() ));
341 action->setData( QVariant() );
342
343 if (types.count() > 1)
344 for (int i=0; i < types.count(); i++){
345 action = menu.addAction(icon, tr("Show all of type '") + dataTypeName(types[i]) + "'",this,SLOT ( showAll() ));
346 action->setData( QVariant( types[i].value() ) );
347 }
348
349 menu.addSeparator();
350 action = menu.addAction(tr("Hide all"),this,SLOT ( hideAll() ));
351 action->setData( QVariant() );
352
353 if (types.count() > 1)
354 for (int i=0; i < types.count(); i++){
355 action = menu.addAction(tr("Hide all of type '") + dataTypeName(types[i]) + "'",this,SLOT ( hideAll() ));
356 action->setData( QVariant( types[i].value() ) );
357 }
358
359 break;
360 // Source
361 case 2 :
362 action = menu.addAction(tr("Select all"),this,SLOT ( setAllSource() ));
363 action->setData( QVariant() );
364
365 if (types.count() > 1)
366 for (int i=0; i < types.count(); i++){
367 action = menu.addAction(icon, tr("Select all of type '") + dataTypeName(types[i]) + "'",this,SLOT ( setAllSource() ));
368 action->setData( QVariant( types[i].value() ) );
369 }
370
371 menu.addSeparator();
372 action = menu.addAction(tr("Deselect all"),this,SLOT ( clearAllSource() ));
373 action->setData( QVariant() );
374
375 if (types.count() > 1)
376 for (int i=0; i < types.count(); i++){
377 action = menu.addAction(icon, tr("Deselect all of type '") + dataTypeName(types[i]) + "'",this,SLOT ( clearAllSource() ));
378 action->setData( QVariant( types[i].value() ) );
379 }
380
381 break;
382 // Target
383 case 3 :
384 action = menu.addAction(tr("Select all"),this,SLOT ( setAllTarget() ));
385 action->setData( QVariant() );
386
387 if (types.count() > 1)
388 for (int i=0; i < types.count(); i++){
389 action = menu.addAction(icon, tr("Select all of type '") + dataTypeName(types[i]) + "'",this,SLOT ( setAllTarget() ));
390 action->setData( QVariant( types[i].value() ) );
391 }
392
393 menu.addSeparator();
394 action = menu.addAction(tr("Deselect all"),this,SLOT ( clearAllTarget() ));
395 action->setData( QVariant() );
396
397 if (types.count() > 1)
398 for (int i=0; i < types.count(); i++){
399 action = menu.addAction(icon, tr("Deselect all of type '") + dataTypeName(types[i]) + "'",this,SLOT ( clearAllTarget() ));
400 action->setData( QVariant( types[i].value() ) );
401 }
402
403 break;
404 default :
405 // std::cerr << "def";
406 break;
407 }
408
409 menu.exec(viewHeader_->mapToGlobal( _pos ) );
410 }
411
412
413 //******************************************************************************
414
418 void DataControlPlugin::slotRename(){
419 QItemSelectionModel* selection = view_->selectionModel();
420
421 // Get all selected rows
422 QModelIndexList indexList = selection->selectedRows ( 0 );
423 int selectedRows = indexList.size();
424 if (selectedRows == 1){
425 int id = model_->itemId( indexList[0]);
426 BaseObject* item = 0;
427
428 if ( id != -1 && PluginFunctions::getObject(id,item) ){
429
430 bool ok;
431 QString newName = QInputDialog::getText(0, tr("Rename"),
432 tr("Enter a new name:"), QLineEdit::Normal,
433 item->name(), &ok);
434 if (ok && !newName.isEmpty()){
435 item->setName(newName);
436 view_->resizeColumnToContents(0);
437 }
438 }
439 }
440 }
441
442
443 //******************************************************************************
444
448 void DataControlPlugin::slotCopyMaterialToTargeted() {
449 BaseObject* item = 0;
450
451 //check if it was called from object contextMenu or from the toolBox
452 QAction* action = dynamic_cast< QAction* > ( sender() );
453
454 if ( action ){
455 bool ok = false;
456
457 int id = action->data().toInt(&ok);
458
459 if ( ok && id > 0 )
460 PluginFunctions::getObject(id,item);
461 }
462
463 if ( item == 0 ){
464 // the slot was called from toolbox
465 QItemSelectionModel* selection = view_->selectionModel();
466
467 // Get all selected rows
468 QModelIndexList indexList = selection->selectedRows ( 0 );
469 int selectedRows = indexList.size();
470 if (selectedRows == 1){
471 int id = model_->itemId( indexList[0] );
472
473 if ( id > 0 )
474 PluginFunctions::getObject(id,item);
475 }
476 }
477
478 if ( item != 0 ){
479
480 BaseObjectData* itemData = dynamic_cast< BaseObjectData* > (item);
481 const ACG::SceneGraph::Material &sourceMaterial = itemData->materialNode()->material();
482
483 for (PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS);
484 o_it != PluginFunctions::objectsEnd(); ++o_it) {
485
486 MaterialNode * const materialNode = o_it->materialNode();
487 if (materialNode) {
488 materialNode->material() = sourceMaterial;
489 }
490 }
491
492 emit updateView();
493 }
494 }
495
496 void DataControlPlugin::slotCopyMaterialToClipboard() {
497 BaseObject* item = 0;
498
499 //check if it was called from object contextMenu or from the toolBox
500 QAction* action = dynamic_cast< QAction* > ( sender() );
501
502 if ( action ){
503 bool ok = false;
504
505 int id = action->data().toInt(&ok);
506
507 if ( ok && id > 0 )
508 PluginFunctions::getObject(id,item);
509 }
510
511 if ( item == 0 ){
512 // the slot was called from toolbox
513 QItemSelectionModel* selection = view_->selectionModel();
514
515 // Get all selected rows
516 QModelIndexList indexList = selection->selectedRows ( 0 );
517 int selectedRows = indexList.size();
518 if (selectedRows == 1){
519 int id = model_->itemId( indexList[0] );
520
521 if ( id > 0 )
522 PluginFunctions::getObject(id,item);
523 }
524 }
525
526 if ( item != 0 ){
527
528 BaseObjectData* itemData = dynamic_cast< BaseObjectData* > (item);
529 const ACG::SceneGraph::Material &sourceMaterial = itemData->materialNode()->material();
530
531 const QString materialJson = sourceMaterial.serializeToJson();
532 QApplication::clipboard()->setText(materialJson);
533 }
534 }
535
536 void DataControlPlugin::slotPasteMaterialFromClipboard() {
537 BaseObject* item = 0;
538
539 //check if it was called from object contextMenu or from the toolBox
540 QAction* action = dynamic_cast< QAction* > ( sender() );
541
542 if ( action ){
543 bool ok = false;
544
545 int id = action->data().toInt(&ok);
546
547 if ( ok && id > 0 )
548 PluginFunctions::getObject(id,item);
549 }
550
551 if ( item == 0 ){
552 // the slot was called from toolbox
553 QItemSelectionModel* selection = view_->selectionModel();
554
555 // Get all selected rows
556 QModelIndexList indexList = selection->selectedRows ( 0 );
557 int selectedRows = indexList.size();
558 if (selectedRows == 1){
559 int id = model_->itemId( indexList[0] );
560
561 if ( id > 0 )
562 PluginFunctions::getObject(id,item);
563 }
564 }
565
566 if ( item != 0 ){
567
568 BaseObjectData* itemData = dynamic_cast< BaseObjectData* > (item);
569 ACG::SceneGraph::Material &destMaterial = itemData->materialNode()->material();
570
571 destMaterial.deserializeFromJson(QApplication::clipboard()->text());
572
573 emit updateView();
574 }
575 }
576
577 void DataControlPlugin::slotMaterialProperties(){
578
579 BaseObject* item = 0;
580
581 //check if it was called from object contextMenu or from the toolBox
582 QAction* action = dynamic_cast< QAction* > ( sender() );
583
584 if ( action ){
585 bool ok = false;
586
587 int id = action->data().toInt(&ok);
588
589 if ( ok && id > 0 )
590 PluginFunctions::getObject(id,item);
591 }
592
593 if ( item == 0 ){
594 // the slot was called from toolbox
595 QItemSelectionModel* selection = view_->selectionModel();
596
597 // Get all selected rows
598 QModelIndexList indexList = selection->selectedRows ( 0 );
599 int selectedRows = indexList.size();
600 if (selectedRows == 1){
601 int id = model_->itemId( indexList[0] );
602
603 if ( id > 0 )
604 PluginFunctions::getObject(id,item);
605 }
606 }
607
608 if ( item != 0 ){
609
610 BaseObjectData* itemData = dynamic_cast< BaseObjectData* > (item);
611
612 ACG::QtWidgets::QtMaterialDialog* dialog = new ACG::QtWidgets::QtMaterialDialog( 0, itemData->materialNode() );
613
614 dialog->setWindowFlags(dialog->windowFlags() | Qt::WindowStaysOnTopHint);
615
616 connect(dialog, SIGNAL(signalNodeChanged(ACG::SceneGraph::BaseNode*)),
617 this, SLOT(slotNodeChanged(ACG::SceneGraph::BaseNode*)) );
618
619 dialog->setWindowIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-material.png"));
620
621 dialog->show();
622
623 }
624 }
625
626
627 //******************************************************************************
628
629 void DataControlPlugin::slotNodeChanged( ACG::SceneGraph::BaseNode* /*_node*/ ){
630 emit updateView();
631 }
632
633 //******************************************************************************
634
638 void DataControlPlugin::slotSwitchLight() {
639
640 QItemSelectionModel* selection = view_->selectionModel();
641
642 // Get all selected rows
643 QModelIndexList indexList = selection->selectedRows ( 0 );
644 int selectedRows = indexList.size();
645 if (selectedRows == 1) {
646
647 LightObject* light = 0;
648 int id = model_->itemId( indexList[0]);
649
650 if (id == -1 || !PluginFunctions::getObject( id, light ) )
651 return;
652
653 if(light == 0) return;
654
655 light->lightSource()->enabled() ?
656 light->lightSource()->disable() :
657 light->lightSource()->enable();
658
659 emit updatedObject(id, UPDATE_ALL);
660 }
661 }
662
663 //******************************************************************************
664
668 void DataControlPlugin::slotEditLight() {
669
670 QItemSelectionModel* selection = view_->selectionModel();
671
672 // Get all selected rows
673 QModelIndexList indexList = selection->selectedRows ( 0 );
674 int selectedRows = indexList.size();
675 if (selectedRows == 1) {
676
677 LightObject* light = 0;
678 int id = model_->itemId( indexList[0]);
679
680 if (id == -1 || !PluginFunctions::getObject( id, light ) )
681 return;
682
683 if(light == 0) return;
684
685 LightWidget* widget = new LightWidget( light->lightNode() );
686 widget->setWindowFlags(Qt::WindowStaysOnTopHint);
687 widget->show();
688 }
689 }
690
691 //******************************************************************************
692
696 void DataControlPlugin::slotZoomTo(){
697 QItemSelectionModel* selection = view_->selectionModel();
698
699 // Get all selected rows
700 QModelIndexList indexList = selection->selectedRows ( 0 );
701 int selectedRows = indexList.size();
702 if (selectedRows == 1){
703 BaseObject* item = 0;
704 int id = model_->itemId( indexList[0]);
705
706 if (id == -1 || !PluginFunctions::getObject( id, item) )
707 return;
708
709 if ( item->isGroup() ) {
710 //zoom to all objects in this group
711 QList< BaseObject* > children = item->getLeafs();
712
713 //compute boundingBox
714 bool firstRound = true;
715 ACG::Vec3d bbmin(FLT_MAX,FLT_MAX,FLT_MAX);
716 ACG::Vec3d bbmax(FLT_MIN,FLT_MIN,FLT_MIN);
717
718 for (int i=0; i < children.size(); i++){
719 BaseObjectData* child = dynamic_cast< BaseObjectData* > (children[i]);
720 if (child){
721
722 if ( !child->visible() ){
723 child->show();
724 }
725
726 ACG::Vec3d cur_min;
727 ACG::Vec3d cur_max;
728
729 child->getBoundingBox(cur_min, cur_max);
730
731 if (firstRound){
732 bbmin = cur_min;
733 bbmax = cur_max;
734 firstRound = false;
735 }else{
736 bbmin[0] = std::min( bbmin[0], cur_min[0]);
737 bbmin[1] = std::min( bbmin[1], cur_min[1]);
738 bbmin[2] = std::min( bbmin[2], cur_min[2]);
739 bbmax[0] = std::max( bbmax[0], cur_max[0]);
740 bbmax[1] = std::max( bbmax[0], cur_max[1]);
741 bbmax[2] = std::max( bbmax[0], cur_max[2]);
742 }
743
744 }
745 }
746 //zoom to objects
747 ACG::Vec3d bbcenter = (bbmax + bbmin) * 0.5;
748
749 double bbradius = (bbmax - bbmin).norm();
750
751 ACG::Vec3d eye = bbcenter + (PluginFunctions::eyePos() - bbcenter).normalize() * bbradius ;
752
753 PluginFunctions::flyTo(eye, bbcenter );
754
755 }else{
756 //zoom to object
757 BaseObjectData* obj = dynamic_cast< BaseObjectData* >(item);
758
759 if (obj){
760
761 if ( !obj->visible() )
762 obj->show();
763
764 ACG::Vec3d bbmin;
765 ACG::Vec3d bbmax;
766
767 obj->getBoundingBox(bbmin, bbmax);
768
769 if ((bbmin[0] > bbmax[0]) || (bbmin[1] > bbmax[1]) || (bbmin[2] > bbmax[2])){
770 std::cerr << "Error while computing bounding box!";
771 return;
772 }
773
774 ACG::Vec3d bbcenter = (bbmax + bbmin) * 0.5;
775
776 double bbradius = (bbmax - bbmin).norm();
777
778 ACG::Vec3d eye = bbcenter + (PluginFunctions::eyePos() - bbcenter).normalize() * bbradius ;
779
780 PluginFunctions::flyTo(eye, bbcenter );
781 }
782 }
783 }
784 }
ACG::SceneGraph::LightSource::enabled
bool enabled() const
Get light source status.
Definition: LightNode.cc:143
ACG::SceneGraph::LightSource::disable
void disable()
disable LightSource
Definition: LightNode.cc:140
typeIcon
DLLEXPORT QIcon & typeIcon(DataType _id)
Get an QIcon associated with the given DataType.
Definition: Types.cc:223
DataControlPlugin::slotGroup
void slotGroup()
Called by the popup menu to group items.
Definition: Popup.cc:157
DataControlPlugin::slotUngroup
void slotUngroup()
Called by the popup menu to ungroup items.
Definition: Popup.cc:110
dataTypeName
DLLEXPORT QString dataTypeName(DataType _id)
Get DataType Human readable name ( this name might change. Use the typeName instead! ) ...
Definition: Types.cc:263
PluginFunctions::ALL_OBJECTS
const QStringList ALL_OBJECTS
Iterable object range.
Definition: PluginFunctions.hh:441
DataControlPlugin::slotNodeChanged
void slotNodeChanged(ACG::SceneGraph::BaseNode *_node)
Called when the material properties were changed inside the material dialog.
Definition: Popup.cc:629
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:135
TreeModel::itemName
QString itemName(const QModelIndex &_index) const
Get the name of a TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:535
DataControlPlugin::setAllSource
void setAllSource()
Makes all available objects source.
Definition: DataControlPluginScripting.cc:469
DataControlPlugin::slotCopyMaterialToTargeted
void slotCopyMaterialToTargeted()
Called by the popup menu to copy material properties.
Definition: Popup.cc:448
BaseObjectData
Definition: BaseObjectData.hh:105
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
DataControlPlugin::model_
TreeModel * model_
The Treemodel organizing the data.
Definition: DataControlPlugin.hh:169
DataControlPlugin::view_
QTreeView * view_
Tree view.
Definition: DataControlPlugin.hh:172
DataControlPlugin::groupObjects
int groupObjects(IdList _objectIDs, QString _groupName="")
Group given Objects together.
Definition: DataControlPluginScripting.cc:368
DataControlPlugin::slotSwitchLight
void slotSwitchLight()
Called by the popup menu in order to turn lights on/off.
Definition: Popup.cc:638
DataControlPlugin::popupIndex_
QModelIndex popupIndex_
Index where a popup has been opened.
Definition: DataControlPlugin.hh:263
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PluginFunctions::getObject
bool getObject(int _identifier, BSplineCurveObject *&_object)
Definition: PluginFunctionsBSplineCurve.cc:75
DataControlPlugin::slotZoomTo
void slotZoomTo()
Called by the popup menu to zoom to an object.
Definition: Popup.cc:696
DataControlPlugin::slotCustomContextMenuRequested
void slotCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeView.
Definition: Popup.cc:181
DataControlPlugin::clearAllSource
void clearAllSource()
remove source selection from all objects
Definition: DataControlPluginScripting.cc:513
BaseObjectData::show
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
Definition: BaseObjectData.cc:194
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:269
LightObject::lightNode
LightNode * lightNode()
Get the scenegraph Node.
Definition: LightObject.cc:229
DataControlPlugin::slotHeaderCustomContextMenuRequested
void slotHeaderCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeViews header.
Definition: Popup.cc:315
LightObject
Definition: LightObject.hh:78
DataControlPlugin::slotEditLight
void slotEditLight()
Called by the popup menu in order to edit lights.
Definition: Popup.cc:668
BaseObject::isGroup
bool isGroup() const
Check if object is a group.
Definition: BaseObject.cc:630
ACG::QtWidgets::QtMaterialDialog
Definition: QtMaterialDialog.hh:95
PluginFunctions::TARGET_OBJECTS
const QStringList TARGET_OBJECTS("target")
Iterable object range.
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
TreeItem
Definition: TreeItem.hh:59
DataControlPlugin::showAll
void showAll()
Shows all objects.
Definition: DataControlPluginScripting.cc:561
IdList
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
PluginFunctions::ObjectIterator
Core Data Iterator.
Definition: PluginFunctions.hh:452
DataControlPlugin::slotPasteMaterialFromClipboard
void slotPasteMaterialFromClipboard()
Called by the popup menu to paste material properties from clipboard.
Definition: Popup.cc:536
DataControlPlugin::slotCopyMaterialToClipboard
void slotCopyMaterialToClipboard()
Called by the popup menu to copy material properties to clipboard.
Definition: Popup.cc:496
PluginFunctions::objectsEnd
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsIterator.cc:187
PluginFunctions::eyePos
ACG::Vec3d eyePos(int _viewer)
Get the current viewer position.
Definition: PluginFunctions.cc:902
BaseObject
Definition: BaseObject.hh:94
DataControlPlugin::slotMaterialProperties
void slotMaterialProperties()
Called by the popup menu to set material properties.
Definition: Popup.cc:577
ACG::SceneGraph::MaterialNode::material
ACG::SceneGraph::Material & material()
Get material object reference.
Definition: MaterialNode.hh:543
DataControlPlugin::slotRename
void slotRename()
Called by the popup menu to rename items.
Definition: Popup.cc:418
LightObject::lightSource
LightSource * lightSource()
Definition: LightObject.cc:328
TreeModel::itemId
int itemId(const QModelIndex &_index) const
Get the id of a TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:552
OpenMesh::VectorT
Definition: Vector11T.hh:83
BaseObject::getLeafs
QList< BaseObject * > getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
Definition: BaseObject.cc:578
BaseObjectData::getBoundingBox
void getBoundingBox(ACG::Vec3d &bbmin, ACG::Vec3d &bbmax)
get the bounding box of the object
Definition: BaseObjectData.cc:289
DataControlPlugin::hideAll
void hideAll()
Hides all objects.
Definition: DataControlPluginScripting.cc:535
DataControlPlugin::headerPopupType_
int headerPopupType_
Defines the section of the Popup.
Definition: DataControlPlugin.hh:272
DataControlPlugin::setAllTarget
void setAllTarget()
Makes all available objects target.
Definition: DataControlPluginScripting.cc:447
DataControlPlugin::slotCopy
void slotCopy()
Called by the popup menu to copy items.
Definition: Popup.cc:127
DATA_LIGHT
#define DATA_LIGHT
Definition: Light.hh:64
DataControlPlugin::viewHeader_
QHeaderView * viewHeader_
Pointer to the header to the view widget.
Definition: DataControlPlugin.hh:175
DataControlPlugin::slotPopupRemove
void slotPopupRemove()
Called by the popup menu to remove an object/group.
Definition: Popup.cc:67
OpenMesh::Attributes::Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
ACG::SceneGraph::LightSource::enable
void enable()
enable LightSource
Definition: LightNode.cc:137
LightWidget
Definition: LightWidget.hh:62
BaseObjectData::visible
virtual bool visible()
return visiblity
Definition: BaseObjectData.cc:212
ACG::SceneGraph::Material
Definition: MaterialNode.hh:85
BaseObject::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObject.cc:734
DataControlPlugin::clearAllTarget
void clearAllTarget()
Unselect all objects.
Definition: DataControlPluginScripting.cc:491
ACG::SceneGraph::MaterialNode
Definition: MaterialNode.hh:321
TreeModel::getItem
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:518
PluginFunctions::flyTo
void flyTo(const ACG::Vec3d &_position, const ACG::Vec3d &_center, double _time)
Fly to point and viewing direction (animated).
Definition: PluginFunctions.cc:1059
Menu
Definition: Menu.hh:53
BaseObject::id
int id() const
Definition: BaseObject.cc:201
DataControlPlugin::unGroupObject
bool unGroupObject(int _id)
Definition: DataControlPluginScripting.cc:414