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