Developer Documentation

DataControlPlugin.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 #include "DataControlPlugin.hh"
45
46
47 #include <ACG/QtWidgets/QtMaterialDialog.hh>
48
49 #include <queue>
50
51 #include <ACG/Scenegraph/TranslationManipulatorNode.hh>
52 #include <ACG/Scenegraph/BoundingBoxNode.hh>
53
54 //******************************************************************************
55
56 const ACG::Vec4f base_color (0.0f,0.0f,0.5f,1.0f);
57 const ACG::Vec4f source_color (0.5f,0.0f,0.0f,1.0f);
58 const ACG::Vec4f target_color (0.0f,0.5f,0.2f,1.0f);
59
60 //******************************************************************************
61
62
63
64 DataControlPlugin::DataControlPlugin() :
65 tool_(0),
66 toolIcon_(0),
67 MeshDialogLayout_(0),
68 objectList_(0),
69 locked(false),
70 model_(0),
71 view_(0),
72 viewHeader_(0),
73 onlyDown_(0),
74 onlyUp_(0),
75 columnFromGUI_(-1),
76 headerPopupType_(0),
77 targetAction_(0),
78 sourceAction_(0),
79 removeAction_(0),
80 advancedSettingsBtn_(0)
81 {
82
83 }
84
85
89 void DataControlPlugin::pluginsInitialized() {
90
91 //set the slot descriptions
92 setDescriptions();
93
94 if ( ! OpenFlipper::Options::gui())
95 return;
96
97 QMenu* contextMenu = new QMenu("Object");
98
99 //Target Objects
100 QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-hide-object.png");
101 QAction* hideAction = new QAction(icon, tr("&Hide"), this);
102 hideAction->setStatusTip(tr("Hide object"));
103 connect(hideAction, SIGNAL(triggered()), this, SLOT(slotContextMenuHide()) );
104 contextMenu->addAction(hideAction);
105
106 //Target Objects
107 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-target-object.png");
108 targetAction_ = new QAction(icon, tr("&Target"), this);
109 targetAction_->setCheckable(true);
110 targetAction_->setStatusTip(tr("Set object as target"));
111 connect(targetAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuTarget()) );
112 contextMenu->addAction(targetAction_);
113
114 //Source Objects
115 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-source-object.png");
116 sourceAction_ = new QAction(icon, tr("&Source"), this);
117 sourceAction_->setCheckable(true);
118 sourceAction_->setStatusTip(tr("Set object as source"));
119 connect(sourceAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuSource()) );
120 contextMenu->addAction(sourceAction_);
121
122 contextMenu->addSeparator();
123
124 //Remove Objects
125 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-delete-item.png");
126 removeAction_ = new QAction(icon, tr("&Remove"), this);
127 removeAction_->setCheckable(false);
128 removeAction_->setStatusTip(tr("Remove object"));
129 connect(removeAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuRemove()) );
130 contextMenu->addAction(removeAction_);
131
132 emit addContextMenuItem(contextMenu->menuAction() , DATA_ALL , CONTEXTOBJECTMENU);
133
134 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-material.png");
135 QAction* material = new QAction(icon, tr("Material Properties"), 0);
136 connect (material, SIGNAL( triggered() ), this, SLOT ( slotMaterialProperties() ));
137 emit addContextMenuItem(material , DATA_ALL , CONTEXTOBJECTMENU);
138
139 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-copyToTargets-material.png");
140 QAction* copyMaterial = new QAction(icon, tr("Copy Material Properties to Targeted Objects"), 0);
141 connect (copyMaterial, SIGNAL( triggered() ), this, SLOT ( slotCopyMaterialToTargeted() ));
142 emit addContextMenuItem(copyMaterial , DATA_ALL , CONTEXTOBJECTMENU);
143
144 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-copy-material.png");
145 QAction* copyMaterialToClipboard = new QAction(icon, tr("Copy Material Properties to Clipboard"), 0);
146 connect (copyMaterialToClipboard, SIGNAL( triggered() ), this, SLOT ( slotCopyMaterialToClipboard() ));
147 emit addContextMenuItem(copyMaterialToClipboard , DATA_ALL , CONTEXTOBJECTMENU);
148
149 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-paste-material.png");
150 QAction* pasteMaterialFromClipboard = new QAction(icon, tr("Paste Material Properties from Clipboard"), 0);
151 connect (pasteMaterialFromClipboard, SIGNAL( triggered() ), this, SLOT ( slotPasteMaterialFromClipboard() ));
152 emit addContextMenuItem(pasteMaterialFromClipboard , DATA_ALL , CONTEXTOBJECTMENU);
153
154 PluginFunctions::setDefaultViewObjectMarker (&objectMarker);
155 PluginFunctions::setViewObjectMarker (&objectMarker);
156
157 connect(tool_->lightSources, SIGNAL(toggled(bool)), this, SLOT(slotShowLightSources(bool)));
158 //update light visibility, if layout was changed
159 connect(model_, SIGNAL(layoutChanged ()), this, SLOT(slotShowLightSources()) );
160 connect(model_, SIGNAL(rowsRemoved(const QModelIndex& , int , int )), this, SLOT(slotShowLightSources()));
161 }
162
163
164 //******************************************************************************
165
166 void DataControlPlugin::initializePlugin()
167 {
168 if ( ! OpenFlipper::Options::gui())
169 return;
170
171 tool_ = new DatacontrolToolboxWidget();
172 connect( tool_ , SIGNAL( keyEvent( QKeyEvent* ) ),
173 this , SLOT(slotKeyEvent ( QKeyEvent* ) ));
174 QSize size(300, 300);
175 tool_->resize(size);
176
177 model_ = new TreeModel( );
178
179 view_ = tool_->treeView;
180
181 tool_->treeView->setModel(model_);
182
183 view_->QTreeView::resizeColumnToContents(1);
184 view_->QTreeView::resizeColumnToContents(2);
185 view_->QTreeView::resizeColumnToContents(3);
186
187
188 connect( model_,SIGNAL(dataChangedInside(int,int,const QVariant&) ),
189 this, SLOT( slotDataChanged(int,int,const QVariant&)) );
190
191 connect( model_,SIGNAL( moveBaseObject(int,int) ),
192 this, SLOT( slotMoveBaseObject(int,int) ) );
193
194 connect( view_,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
195 this,SLOT(slotCustomContextMenuRequested ( const QPoint & ) ));
196
197 connect( tool_->notSelected, SIGNAL(toggled ( bool ) ),
198 this, SLOT (slotBoundingBoxChange ( ) ));
199 connect( tool_->sourceSelected, SIGNAL(toggled ( bool ) ),
200 this, SLOT (slotBoundingBoxChange ( ) ));
201 connect( tool_->targetSelected, SIGNAL(toggled ( bool ) ),
202 this, SLOT (slotBoundingBoxChange ( ) ));
203
204 connect( this, SIGNAL(objectsGrouped(IdList)), this, SLOT(slotObjectsGrouped(IdList)),Qt::QueuedConnection);
205
206 viewHeader_ = tool_->treeView->header();
207 viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
208
209 // connect the slot for the context menu
210 connect( viewHeader_, SIGNAL(customContextMenuRequested ( const QPoint & ) ),
211 this, SLOT(slotHeaderCustomContextMenuRequested ( const QPoint & ) ));
212
213 toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-toolbox.png");
214
215 QWidget *headerAreaWidget = new QWidget();
216 advancedSettingsBtn_ = new QToolButton();
217 advancedSettingsBtn_->setAutoRaise(true);
218 advancedSettingsBtn_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"preferences.png"));
219 advancedSettingsBtn_->setIconSize(QSize(16, 16));
220 advancedSettingsBtn_->setPopupMode(QToolButton::InstantPopup);
221 advancedSettingsBtn_->setToolTip(tr("Advanced Settings"));
222 QHBoxLayout *hl = new QHBoxLayout;
223 hl->addWidget(advancedSettingsBtn_);
224 hl->addStretch(1);
225 hl->setContentsMargins(8, 0, 0, 0);
226 headerAreaWidget->setLayout(hl);
227
228 QMenu *menu = new QMenu();
229 menu->addAction(tool_->lightSources);
230 menu->addAction(tool_->notSelected);
231 menu->addAction(tool_->sourceSelected);
232 menu->addAction(tool_->targetSelected);
233 advancedSettingsBtn_->setMenu(menu);
234
235 emit addToolbox("Data Control", tool_, toolIcon_, headerAreaWidget);
236 }
237
238 //******************************************************************************
239
243 void DataControlPlugin::slotObjectsGrouped(IdList _lst)
244 {
245 // Get all selected rows
246 int selectedRows = _lst.size();
247
248 //update each item
249 for(int i = 0 ; i < selectedRows ; ++i)
250 {
251 int id = _lst[i];
252 BaseObject* item = 0;
253
254 if ( id != -1 && PluginFunctions::getObject(id,item) )
255 emit updatedObject(item->id(),UPDATE_ALL);
256 }
257 }
258
259 //******************************************************************************
260
264 void DataControlPlugin::slotObjectSelectionChanged( int _identifier )
265 {
266 if ( ! OpenFlipper::Options::gui())
267 return;
268
269 BaseObjectData* obj = 0;
270
271 if ( PluginFunctions::getObject( _identifier, obj) )
272 updateBoundingBox (obj);
273
274 BaseObject* object = 0;
275 if ( !PluginFunctions::getObject( _identifier, object) )
276 return;
277
278 //check for changes
279 int column = columnFromGUI_;//if GUI has set the column, use this information
280 if (column == -1)//otherwise, try to get the column
281 {
282 TreeItem* item = model_->getItem(_identifier);
283 if ( !item )
284 return;
285
286 if (item->source() != object->source())
287 column = 2;
288 else if (item->target() != object->target())
289 column = 3;
290 else
291 return;//could not decide, which column needs a update, discard
292 }
293
294
295 model_->objectChanged( _identifier );
296
297 //block scenegraph reset and redraw in core
298 OpenFlipper::Options::blockSceneGraphUpdates();
299 OpenFlipper::Options::redrawDisabled(true);
300
301 // if we are allowed to propagate down
302 if ( onlyUp_ == 0 ){
303
304 onlyDown_++;
305
306 if ( object->isGroup() )
307 propagateDownwards(object, column); // 2: source 3: target
308
309 onlyDown_--;
310 }
311
312 // if we are allowed to propagate up
313 if ( onlyDown_ == 0 ){
314
315 onlyUp_++;
316
317 propagateUpwards(object->parent(), column); // 2: source 3: target
318
319 onlyUp_--;
320 }
321
322 OpenFlipper::Options::unblockSceneGraphUpdates();
323 OpenFlipper::Options::redrawDisabled(false);
324 emit updateView();
325 }
326
327
328 //******************************************************************************
329
334 void DataControlPlugin::slotVisibilityChanged( int _identifier ){
335
336 if ( ! OpenFlipper::Options::gui())
337 return;
338
339 // if onlyUp_ > 0 --> _identifier is a group and the selection
340 // does not have to be applied
341 if (onlyUp_ == 0){
342 //inform the model
343 model_->objectChanged( _identifier );
344 }
345
346 //check for changes in the tree
347 BaseObject* obj = 0;
348
349 //block scenegraph reset and redraw in core
350 OpenFlipper::Options::blockSceneGraphUpdates();
351 OpenFlipper::Options::redrawDisabled(true);
352
353 if ( PluginFunctions::getObject( _identifier, obj) ){
354
355 // if we are allowed to propagate up
356 if ( onlyDown_ == 0 ){
357
358 onlyUp_++;
359
360 propagateUpwards(obj->parent(), 1); // 1 = visibilty
361
362 onlyUp_--;
363
364 }
365
366 // if we are allowed to propagate down
367 if ( onlyUp_ == 0 ){
368
369 onlyDown_++;
370
371 if ( obj->isGroup() )
372 propagateDownwards(obj, 1); // 1 = visibilty
373
374 onlyDown_--;
375 }
376 }
377
378 OpenFlipper::Options::unblockSceneGraphUpdates();
379 OpenFlipper::Options::redrawDisabled(false);
380
381 BaseObjectData* object = 0;
382
383 if ( PluginFunctions::getObject( _identifier, object) )
384 updateBoundingBox (object);
385
386 emit updateView();
387
388 }
389
390
391 //******************************************************************************
392
397 void DataControlPlugin::slotObjectPropertiesChanged( int _identifier ){
398
399 if ( ! OpenFlipper::Options::gui())
400 return;
401
402 model_->objectChanged( _identifier );
403 }
404
405
406 //******************************************************************************
407
412 void DataControlPlugin::fileOpened(int _id){
413
414 if ( ! OpenFlipper::Options::gui())
415 return;
416
417 BaseObject* obj = 0;
418
419 if ( PluginFunctions::getObject(_id, obj) ) {
420 model_->objectAdded(obj);
421
422 // Only if the added object was a light source, we will traverse the objects!
423 if ( obj->dataType() == DATA_LIGHT)
424 slotShowLightSources(tool_->lightSources->isChecked());
425
426 view_->resizeColumnToContents(0);
427 }
428 }
429
430
431 //******************************************************************************
432
437 void DataControlPlugin::addedEmptyObject(int _id){
438 fileOpened(_id);
439 }
440
441 //******************************************************************************
442
447 void DataControlPlugin::objectDeleted(int _id){
448
449 if ( ! OpenFlipper::Options::gui())
450 return;
451
452 model_->objectDeleted(_id);
453 }
454
455 //******************************************************************************
456
461 void DataControlPlugin::slotKeyEvent( QKeyEvent* _event )
462 {
463
464 if ( _event->modifiers() == Qt::ControlModifier ) {
465 switch (_event->key()) {
466 case Qt::Key_A :
467 setAllTarget();
468 return;
469 default:
470 return;
471 }
472 }
473
474 switch (_event->key()) {
475 case Qt::Key_Delete :
476 slotPopupRemove();
477 return;
478 default:
479 return;
480 }
481
482 }
483
484
485 //******************************************************************************
486
493 void DataControlPlugin::slotDataChanged ( int _id, int _column, const QVariant& _value)
494 {
495
496 //get the corresponding baseObject
497 BaseObject* obj = 0;
498 if ( !PluginFunctions::getObject( _id, obj) )
499 return;
500
501 switch ( _column ) {
502 // Name
503 case 0:
504 obj->setName( _value.toString() );
505 break;
506
507 // show/hide
508 case 1:
509 obj->visible( _value.toBool() );
510 break;
511
512 // source
513 case 2:
514 columnFromGUI_ = 2;//set information, which information will be changed
515 obj->source( _value.toBool() );
516 columnFromGUI_ = -1;
517 break;
518
519 // target
520 case 3:
521 columnFromGUI_ = 3;//set information, which information will be changed
522 obj->target( _value.toBool() );
523 columnFromGUI_ = -1;
524 break;
525
526 default:
527 break;
528 }
529 }
530
531
532 //******************************************************************************
533
539 void DataControlPlugin::slotMoveBaseObject(int _id, int _newParentId){
540
541 BaseObject* obj = 0;
542
543 if ( !PluginFunctions::getObject(_id, obj) )
544 return;
545
546 BaseObject* parent = 0;
547
548 if ( !PluginFunctions::getObject(_newParentId, parent) )
549 return;
550
551 BaseObject* oldParent = obj->parent();
552
553 //set new parent
554 obj->setParent( parent );
555
556 //if oldParent is an empty group -> delete it
557 if ( oldParent != PluginFunctions::objectRoot() && oldParent->childCount() == 0 )
558 emit deleteObject( oldParent->id() );
559 }
560
561
562 //******************************************************************************
563
564 void DataControlPlugin::slotShowLightSources( bool _state ) {
565
566 int rows = model_->rowCount();
567
568 for(int i = 0; i < rows; ++i) {
569 TreeItem* item = model_->getItem(model_->index(i,0));
570 if(item->dataType() == DATA_LIGHT) {
571 view_->setRowHidden(i, model_->parent(model_->index(i,0)), !_state);
572 }else{
573 //always show, if it is not a light
574 view_->setRowHidden(i, model_->parent(model_->index(i,0)), false);
575 }
576 }
577 }
578
579
580 void DataControlPlugin::slotShowLightSources()
581 {
582 slotShowLightSources( tool_->lightSources->isChecked() );
583 }
584 //******************************************************************************
585
590 void DataControlPlugin::loadIniFileOptionsLast( INIFile& _ini ) {
591
592 if ( _ini.section_exists( "BoundingBox" ) && OpenFlipper::Options::gui() )
593 {
594 bool value;
595 if (_ini.get_entry(value, "BoundingBox","notSelected"))
596 tool_->notSelected->setChecked (value);
597 if (_ini.get_entry(value, "BoundingBox","sourceSelected"))
598 tool_->sourceSelected->setChecked (value);
599 if (_ini.get_entry(value, "BoundingBox","targetSelected"))
600 tool_->targetSelected->setChecked (value);
601 }
602
603 if ( !_ini.section_exists( "Groups" ) )
604 return;
605
606 // Names of all groups
607 QStringList groupNames;
608
609 // names of the primary groups
610 QStringList rootGroup;
611
612 // Get the list of group names to the file
613 _ini.get_entry(groupNames,"Groups","groups");
614
615 // Get the primary group names to the file
616 _ini.get_entry(rootGroup,"Groups","rootGroup");
617
618 //list of groups
619 QVector< BaseObject* > groups;
620
621 // Go over one level of the groups
622 while ( rootGroup.size() > 0 ) {
623 QString current = rootGroup[0];
624 rootGroup.removeFirst();
625
626 QStringList groupChildren;
627 QStringList elementChildren;
628
629 _ini.get_entry(elementChildren ,current,"children");
630 _ini.get_entry(groupChildren ,current,"subgroups");
631
632 // if we get a parent item, scan the tree for it or use the root node otherwise
633 BaseObject* parentItem;
634 QString parentName;
635 if ( _ini.get_entry(parentName,current,"parent") ) {
636 parentItem = PluginFunctions::objectRoot()->childExists(parentName);
637 if ( parentItem == 0 )
638 parentItem = PluginFunctions::objectRoot();
639 } else
640 parentItem = PluginFunctions::objectRoot();
641
642 rootGroup << groupChildren;
643
644 // check if this group already exists
645 BaseObject* group = PluginFunctions::objectRoot()->childExists( current );
646
647 // group does not exist
648 if ( !group ) {
649
650 int groupId = addEmptyGroup(current, parentItem->id());
651 PluginFunctions::getObject(groupId, group);
652
653 // in the groups vector we only need the lowest groups
654 // because they are used recursively
655 int p = groups.indexOf( group->parent() );
656 if ( p > -1 )
657 groups.remove( p );
658
659 groups.push_back( group );
660 }
661
662 // process children
663 for ( int i = 0 ; i < elementChildren.size() ; ++i ) {
664 BaseObject* childItem = PluginFunctions::objectRoot()->childExists( elementChildren[i] );
665 if ( childItem ) {
666 childItem->setParent(group);
667 }
668 }
669 }
670 }
671
672
673 //******************************************************************************
674
679 void DataControlPlugin::saveIniFileOptions( INIFile& _ini ) {
680
681 std::queue< BaseObject* > children;
682 children.push( PluginFunctions::objectRoot() );
683
684 std::vector< BaseObject* > groups;
685
686 // Get all groups from the tree
687 while ( ! children.empty() ) {
688 BaseObject* item = children.front();
689 children.pop();
690
691 for ( int i = 0 ; i < item->childCount(); ++i )
692 if ( item->child(i)->dataType(DATA_GROUP))
693 children.push( item->child(i) );
694
695 if ( item->dataType(DATA_GROUP) && (item != PluginFunctions::objectRoot() ) )
696 groups.push_back(item);
697 }
698
699 // Names of all groups
700 QStringList groupNames;
701
702 // names of the primary groups
703 QStringList rootGroup;
704
705 for ( uint i = 0 ; i < groups.size() ; ++i ) {
706 groupNames.push_back( groups[i]->name() );
707
708 _ini.add_entry(groups[i]->name(),"groupname",groups[i]->name());
709
710 // write the name of the parent
711 if ( ( groups[i]->parent() != 0 ) && ( groups[i]->parent() != PluginFunctions::objectRoot() ) )
712 _ini.add_entry(groups[i]->name(),"parent",groups[i]->parent()->name());
713
714 if ( groups[i]->parent() == PluginFunctions::objectRoot() )
715 rootGroup.push_back( groups[i]->name() );
716
717 // Write a list of this groups children
718 QStringList groupchildren;
719 QStringList elementchildren;
720 for ( int j = 0 ; j < groups[i]->childCount(); ++j ) {
721 if ( groups[i]->child(j)->dataType(DATA_GROUP) )
722 groupchildren.push_back( groups[i]->child(j)->name() );
723 else
724 elementchildren.push_back( groups[i]->child(j)->name() );
725 }
726
727 _ini.add_entry(groups[i]->name(),"subgroups",groupchildren);
728 _ini.add_entry(groups[i]->name(),"children",elementchildren);
729 }
730
731 // Write the list of group names to the file
732 _ini.add_entry("Groups","groups",groupNames);
733
734 // Write the primary group names to the file
735 _ini.add_entry("Groups","rootGroup",rootGroup);
736
737 if ( OpenFlipper::Options::gui() ) {
738
739 _ini.add_entry("BoundingBox","notSelected",tool_->notSelected->isChecked ());
740 _ini.add_entry("BoundingBox","sourceSelected",tool_->sourceSelected->isChecked ());
741 _ini.add_entry("BoundingBox","targetSelected",tool_->targetSelected->isChecked ());
742 }
743
744 }
745
746
747 //******************************************************************************
748
754 void DataControlPlugin::propagateUpwards(BaseObject* _obj, int _column ){
755
756
757 if ( _obj == PluginFunctions::objectRoot() || (!_obj->isGroup()) )
758 return;
759
760 QList< BaseObject* > children = _obj->getLeafs();
761 bool changed = false;
762 bool value = false;
763
764
765 switch ( _column ){
766
767 case 1: //VISIBILTY
768
769 for (int i=0; i < children.size(); i++)
770 value |= children[i]->visible();
771
772 _obj->visible( value );
773
774 changed = true;
775
776 break;
777
778 case 2: //SOURCE
779
780 for (int i=0; i < children.size(); i++){
781 value |= children[i]->source();
782 }
783
784 if (_obj->source() != value){
785 _obj->source( value );
786 changed = true;
787 }
788 break;
789
790 case 3: //TARGET
791
792 for (int i=0; i < children.size(); i++){
793 value |= children[i]->target();
794 }
795
796 if (_obj->target() != value){
797 _obj->target( value );
798 changed = true;
799 }
800
801 break;
802
803 default:
804 break;
805 }
806
807 if ( changed )
808 propagateUpwards( _obj->parent(), _column );
809 }
810
811 //******************************************************************************
812
818 void DataControlPlugin::propagateDownwards(BaseObject* _obj, int _column ){
819
820 for (int i=0; i < _obj->childCount(); i++){
821
822 BaseObject* current = _obj->child(i);
823
824 switch ( _column ){
825
826 case 1: //VISIBILTY
827
828 if ( current->visible() != _obj->visible() ){
829
830 current->visible( _obj->visible() );
831 }
832 break;
833
834 case 2: //SOURCE
835
836 if ( current->source() != _obj->source() ){
837 current->source( _obj->source() );
838 }
839 break;
840
841 case 3: //TARGET
842
843 if ( current->target() != _obj->target() ){
844 current->target( _obj->target() );
845 }
846
847 break;
848
849 default:
850 break;
851 }
852
853 if ( current->isGroup() ){
854 propagateDownwards(current, _column);
855
856 }
857 }
858 }
859
860 //******************************************************************************
861
864 void DataControlPlugin::slotBoundingBoxChange( )
865 {
866 for (PluginFunctions::ObjectIterator o_it; o_it != PluginFunctions::objectsEnd(); ++o_it) {
867 updateBoundingBox (o_it);
868 }
869
870 emit updateView();
871 }
872
873 //******************************************************************************
874
879 void DataControlPlugin::updateBoundingBox(BaseObjectData* _obj)
880 {
881 if (tool_->notSelected->isChecked () ||
882 (_obj->source () && tool_->sourceSelected->isChecked ()) ||
883 (_obj->target () && tool_->targetSelected->isChecked ()))
884 {
885 _obj->boundingBoxNode()->set_status( ACG::SceneGraph::BaseNode::Active );
886
887 ACG::Vec4f color = base_color;
888
889 if (_obj->source () && tool_->sourceSelected->isChecked ())
890 color += source_color;
891
892 if (_obj->target () && tool_->targetSelected->isChecked ())
893 color += target_color;
894
895 _obj->boundingBoxNode()->set_base_color (color);
896 }
897 else
898 _obj->boundingBoxNode()->set_status( ACG::SceneGraph::TranslationManipulatorNode::HideNode );
899
900 }
901
902 //******************************************************************************
907 void DataControlPlugin::saveOnExit(INIFile& _ini){
908 _ini.add_entry("BoundingBox","notSelected",tool_->notSelected->isChecked ());
909 _ini.add_entry("BoundingBox","sourceSelected",tool_->sourceSelected->isChecked ());
910 _ini.add_entry("BoundingBox","targetSelected",tool_->targetSelected->isChecked ());
911 }
912
913 void DataControlPlugin::showReducedUi(bool reduced) {
914 if (advancedSettingsBtn_)
915 advancedSettingsBtn_->setVisible(reduced);
916 }
917
918 void DataControlPlugin::slotObjectUpdated( int _identifier, const UpdateType& _type )
919 {
920 if ( ! OpenFlipper::Options::gui() || !_type.contains(UPDATE_GEOMETRY))
921 return;
922
923 BaseObjectData* obj = 0;
924
925 if ( PluginFunctions::getObject( _identifier, obj) )
926 {
927 updateBoundingBox (obj);
928 model_->objectChanged(obj->id());
929 }
930 }
931
932
DataControlPlugin::slotKeyEvent
void slotKeyEvent(QKeyEvent *_event)
a key event occurred
Definition: DataControlPlugin.cc:461
TreeItem::dataType
DataType dataType()
dataType
Definition: TreeItem.cc:94
DataControlPlugin::slotVisibilityChanged
void slotVisibilityChanged(int _identifier)
Update the model if the visibility of an object changed.
Definition: DataControlPlugin.cc:334
DataControlPlugin::propagateUpwards
void propagateUpwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
Definition: DataControlPlugin.cc:754
DataControlPlugin::saveIniFileOptions
void saveIniFileOptions(INIFile &_ini)
Save groups to ini file.
Definition: DataControlPlugin.cc:679
BaseObject::getLeafs
QList< BaseObject *> getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
Definition: BaseObject.cc:567
UPDATE_GEOMETRY
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
BaseObject::child
BaseObject * child(int row)
return a child
Definition: BaseObject.cc:506
DataControlPlugin::slotBoundingBoxChange
void slotBoundingBoxChange()
Bounding box selection changed.
Definition: DataControlPlugin.cc:864
TreeItem::target
bool target()
target
Definition: TreeItem.cc:127
BaseObject::source
bool source()
Definition: BaseObject.cc:291
DataControlPlugin::columnFromGUI_
int columnFromGUI_
Gets called when the data in the table has changed.
Definition: DataControlPlugin.hh:201
DataControlPlugin::loadIniFileOptionsLast
void loadIniFileOptionsLast(INIFile &_ini)
Load Groups from ini file.
Definition: DataControlPlugin.cc:590
BaseObject::childCount
int childCount() const
get the number of children
Definition: BaseObject.cc:511
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
DataControlPlugin::objectMarker
DefaultObjectMarker objectMarker
Default marker to visualize "source" and "target" object flags.
Definition: DataControlPlugin.hh:176
DataControlPlugin::onlyUp_
int onlyUp_
Gets called when the data in the table has changed.
Definition: DataControlPlugin.hh:198
DatacontrolToolboxWidget
Definition: Toolbox.hh:46
INIFile::add_entry
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Definition: INIFile.cc:257
DataControlPlugin::viewHeader_
QHeaderView * viewHeader_
Pointer to the header to the view widget.
Definition: DataControlPlugin.hh:173
BaseObject
Definition: BaseObject.hh:82
DataControlPlugin::slotContextMenuTarget
void slotContextMenuTarget()
Target Selection.
Definition: ContextMenuDataControl.cc:49
DataControlPlugin::slotCopyMaterialToTargeted
void slotCopyMaterialToTargeted()
Called by the popup menu to copy material properties.
Definition: Popup.cc:446
DataControlPlugin::objectDeleted
void objectDeleted(int _id)
an object was deleted. delete it internally
Definition: DataControlPlugin.cc:447
DataControlPlugin::targetAction_
QAction * targetAction_
Hide an object.
Definition: DataControlPlugin.hh:297
TreeModel::parent
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
Definition: TreeModel.cc:312
DataControlPlugin::slotObjectPropertiesChanged
void slotObjectPropertiesChanged(int _identifier)
Update the model if properties of an object changed.
Definition: DataControlPlugin.cc:397
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
PluginFunctions::objectRoot
BaseObject *& objectRoot()
Get the root of the object structure.
Definition: PluginFunctions.cc:1101
OpenMesh::VectorT
Definition: Vector11T.hh:83
BaseObject::target
bool target()
Definition: BaseObject.cc:273
DATA_GROUP
const DataType DATA_GROUP(1)
Items used for Grouping.
INIFile::get_entry
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
Definition: INIFile.cc:433
DataControlPlugin::DataControlPlugin
DataControlPlugin()
Constructor.
Definition: DataControlPlugin.cc:64
DataControlPlugin::slotCopyMaterialToClipboard
void slotCopyMaterialToClipboard()
Called by the popup menu to copy material properties to clipboard.
Definition: Popup.cc:494
ACG::SceneGraph::BaseNode::Active
Draw node & children.
Definition: BaseNode.hh:392
DataControlPlugin::setAllTarget
void setAllTarget()
Makes all available objects target.
Definition: DataControlPluginScripting.cc:447
DataControlPlugin::removeAction_
QAction * removeAction_
Hide an object.
Definition: DataControlPlugin.hh:299
BaseObject::id
int id() const
Definition: BaseObject.cc:190
DataControlPlugin::showReducedUi
void showReducedUi(bool reduced)
Show or hide the extended ui interface in the datacontrol toolbox.
Definition: DataControlPlugin.cc:913
DataControlPlugin::slotDataChanged
void slotDataChanged(int _id, int _column, const QVariant &_value)
Gets called when the data in the table has changed.
Definition: DataControlPlugin.cc:493
TreeModel::getItem
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:508
DataControlPlugin::sourceAction_
QAction * sourceAction_
Hide an object.
Definition: DataControlPlugin.hh:298
DataControlPlugin::slotHeaderCustomContextMenuRequested
void slotHeaderCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeViews header.
Definition: Popup.cc:313
BaseObject::childExists
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
Definition: BaseObject.cc:516
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
DataControlPlugin::advancedSettingsBtn_
QToolButton * advancedSettingsBtn_
Hide an object.
Definition: DataControlPlugin.hh:301
PluginFunctions::setDefaultViewObjectMarker
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
Definition: PluginFunctions.cc:948
IdList
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:179
PluginFunctions::objectsEnd
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsIterator.cc:177
DataControlPlugin::model_
TreeModel * model_
The Treemodel organizing the data.
Definition: DataControlPlugin.hh:167
TreeModel::index
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
Definition: TreeModel.cc:285
BaseObject::parent
BaseObject * parent()
Get the parent item ( 0 if rootitem )
Definition: BaseObject.cc:466
DataControlPlugin::view_
QTreeView * view_
Tree view.
Definition: DataControlPlugin.hh:170
TreeItem::source
bool source()
source
Definition: TreeItem.cc:139
BaseObjectData::boundingBoxNode
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
Definition: BaseObjectData.cc:271
BaseObject::setParent
void setParent(BaseObject *_parent)
Set the parent pointer.
Definition: BaseObject.cc:477
BaseObject::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObject.cc:723
PluginFunctions::setViewObjectMarker
void setViewObjectMarker(ViewObjectMarker *_marker)
Definition: PluginFunctions.cc:942
DataControlPlugin::slotMoveBaseObject
void slotMoveBaseObject(int _id, int _newParentId)
Gets called when an object was moved via drag n drop.
Definition: DataControlPlugin.cc:539
PluginFunctions::ObjectIterator
Core Data Iterator.
Definition: PluginFunctions.hh:441
DataControlPlugin::slotContextMenuRemove
void slotContextMenuRemove()
Remove Selected Item.
Definition: ContextMenuDataControl.cc:92
TreeItem
Definition: TreeItem.hh:52
DataControlPlugin::slotCustomContextMenuRequested
void slotCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeView.
Definition: Popup.cc:179
BaseObjectData
Definition: BaseObjectData.hh:102
UpdateType
Update type class.
Definition: UpdateType.hh:60
DataControlPlugin::name
QString name()
Name of the Plugin.
Definition: DataControlPlugin.hh:147
ACG::SceneGraph::ACG::SceneGraph::BaseNode::set_status
void set_status(StatusMode _s)
Set the status of this node.
Definition: MeshNode2T_impl.hh:403
TreeModel
Definition: TreeModel.hh:53
DataControlPlugin::tool_
DatacontrolToolboxWidget * tool_
Widget for Toolbox.
Definition: DataControlPlugin.hh:150
DataControlPlugin::fileOpened
void fileOpened(int _id)
Update the model if a file has been opened.
Definition: DataControlPlugin.cc:412
BaseObject::isGroup
bool isGroup() const
Check if object is a group.
Definition: BaseObject.cc:619
TreeModel::objectDeleted
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
Definition: TreeModel.cc:461
UpdateType::contains
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:104
DataControlPlugin::slotContextMenuSource
void slotContextMenuSource()
Source Selection.
Definition: ContextMenuDataControl.cc:78
DataControlPlugin::onlyDown_
int onlyDown_
Gets called when the data in the table has changed.
Definition: DataControlPlugin.hh:197
TreeModel::objectChanged
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
Definition: TreeModel.cc:353
DataControlPlugin::slotShowLightSources
void slotShowLightSources()
Index where a popup has been opened.
Definition: DataControlPlugin.cc:580
DataControlPlugin::slotObjectsGrouped
void slotObjectsGrouped(IdList _lst)
update objects when they have been grouped
Definition: DataControlPlugin.cc:243
DataControlPlugin::slotContextMenuHide
void slotContextMenuHide()
Hide an object.
Definition: ContextMenuDataControl.cc:63
INIFile
Class for the handling of simple configuration files.
Definition: INIFile.hh:99
ACG::SceneGraph::MaterialNode::set_base_color
void set_base_color(const Vec4f &_c)
set the base color ( Same as set_emission(const Vec4f& _c) )
Definition: MaterialNode.hh:421
DataControlPlugin::saveOnExit
void saveOnExit(INIFile &_ini)
Save settings before application is closed.
Definition: DataControlPlugin.cc:907
BaseObject::visible
virtual bool visible()
return if object is visible
Definition: BaseObject.cc:339
DataControlPlugin::slotObjectSelectionChanged
void slotObjectSelectionChanged(int _identifier)
update drawing of objects when the active object changed
Definition: DataControlPlugin.cc:264
TreeModel::rowCount
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
Definition: TreeModel.cc:334
DataControlPlugin::setDescriptions
void setDescriptions()
Definition: DataControlPluginScripting.cc:52
DataControlPlugin::addedEmptyObject
void addedEmptyObject(int _id)
Update the model if an empty object has been added.
Definition: DataControlPlugin.cc:437
DataControlPlugin::slotMaterialProperties
void slotMaterialProperties()
Called by the popup menu to set material properties.
Definition: Popup.cc:575
DATA_LIGHT
#define DATA_LIGHT
Definition: Light.hh:58
TreeModel::objectAdded
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
Definition: TreeModel.cc:426
DataControlPlugin::propagateDownwards
void propagateDownwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
Definition: DataControlPlugin.cc:818
INIFile::section_exists
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
Definition: INIFile.cc:227
DataControlPlugin::updateBoundingBox
void updateBoundingBox(BaseObjectData *_obj)
Updates bounding box.
Definition: DataControlPlugin.cc:879
DataControlPlugin::slotPasteMaterialFromClipboard
void slotPasteMaterialFromClipboard()
Called by the popup menu to paste material properties from clipboard.
Definition: Popup.cc:534
DataControlPlugin::pluginsInitialized
void pluginsInitialized()
Plugin initialization.
Definition: DataControlPlugin.cc:89
CONTEXTOBJECTMENU
The Menu will be shown when an object was picked.
Definition: ContextMenuInterface.hh:59
DATA_ALL
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
ACG::SceneGraph::ACG::SceneGraph::BaseNode::HideNode
Hide this node, but draw children.
Definition: MeshNode2T_impl.hh:394
DataControlPlugin::addEmptyGroup
int addEmptyGroup(QString _groupName="", int _parentGroupId=0)
Create new empty group.
Definition: DataControlPluginScripting.cc:328
DataControlPlugin::slotPopupRemove
void slotPopupRemove()
Called by the popup menu to remove an object/group.
Definition: Popup.cc:62