DataControlPlugin.cc 19.9 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16
17
18
19
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================





#include <QtGui>

#include "DataControlPlugin.hh"

#include <QLayout>
41
#include <QGridLayout>
Jan Möbius's avatar
 
Jan Möbius committed
42
#include <QItemSelectionModel>
43

Jan Möbius's avatar
 
Jan Möbius committed
44
45
46
47
#include <iostream>
#include <ACG/GL/GLState.hh>
#include <QStringList>
#include <ACG/Scenegraph/BaseNode.hh>
Dirk Wilden's avatar
Dirk Wilden committed
48
#include <ACG/QtWidgets/QtMaterialDialog.hh>
Jan Möbius's avatar
 
Jan Möbius committed
49
50
51
52
53
#include <QModelIndexList>

#include <queue>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
54
#include <OpenFlipper/common/GlobalOptions.hh>
Jan Möbius's avatar
 
Jan Möbius committed
55

Dirk Wilden's avatar
Dirk Wilden committed
56
//******************************************************************************
Dirk Wilden's avatar
Dirk Wilden committed
57

58
59
60
61
62
63
const ACG::Vec4f base_color (0.0,0.0,0.5,1.0);
const ACG::Vec4f source_color (0.5,0.0,0.0,1.0);
const ACG::Vec4f target_color (0.0,0.5,0.2,1.0);

//******************************************************************************

Dirk Wilden's avatar
Dirk Wilden committed
64
/** \brief Plugin initialization
65
 *
Dirk Wilden's avatar
Dirk Wilden committed
66
 */
Jan Möbius's avatar
 
Jan Möbius committed
67
void DataControlPlugin::pluginsInitialized() {
68

Jan Möbius's avatar
   
Jan Möbius committed
69
70
71
  //set the slot descriptions
  setDescriptions();

Jan Möbius's avatar
 
Jan Möbius committed
72
  QMenu* contextMenu = new QMenu("Object selection");
73

Jan Möbius's avatar
 
Jan Möbius committed
74
75
76
77
78
  //Target Objects
  QAction* hideAction = new QAction(tr("&Hide"), this);
  hideAction->setStatusTip(tr("Hide object"));
  connect(hideAction, SIGNAL(triggered()), this, SLOT(slotContextMenuHide()) );
  contextMenu->addAction(hideAction);
79

Jan Möbius's avatar
 
Jan Möbius committed
80
81
82
83
84
85
  //Target Objects
  targetAction_ = new QAction(tr("&target"), this);
  targetAction_->setCheckable(true);
  targetAction_->setStatusTip(tr("Set object as target"));
  connect(targetAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuTarget()) );
  contextMenu->addAction(targetAction_);
86

Jan Möbius's avatar
 
Jan Möbius committed
87
88
89
90
91
  //Source Objects
  sourceAction_ = new QAction(tr("&source"), this);
  sourceAction_->setCheckable(true);
  sourceAction_->setStatusTip(tr("Set object as source"));
  connect(sourceAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuSource()) );
92
93
  contextMenu->addAction(sourceAction_);

Jan Möbius's avatar
   
Jan Möbius committed
94
  emit addContextMenuItem(contextMenu->menuAction() , DATA_ALL , CONTEXTOBJECTMENU);
95

96
97
98
99
100
  QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-material.png");
  QAction* material = new QAction(icon, "Material Properties", 0);
  connect (material, SIGNAL( triggered() ), this, SLOT ( slotMaterialProperties() ));

  emit addContextMenuItem(material , DATA_ALL , CONTEXTOBJECTMENU);
101
102
103

  PluginFunctions::setDefaultViewObjectMarker (&objectMarker);
  PluginFunctions::setViewObjectMarker (&objectMarker);
Jan Möbius's avatar
 
Jan Möbius committed
104
105
}

Dirk Wilden's avatar
Dirk Wilden committed
106
107
108
109

//******************************************************************************

/** \brief initialize the toolBox
110
 *
Dirk Wilden's avatar
Dirk Wilden committed
111
112
113
 * @param _widget a reference to the toolBox
 * @return returns if the toolbox was created successfully
 */
Jan Möbius's avatar
 
Jan Möbius committed
114
115
116
bool DataControlPlugin::initializeToolbox(QWidget*& _widget)
{
   locked = false;
117
118
119
   tool_ = new DatacontrolToolboxWidget();
   connect( tool_ , SIGNAL( keyEvent( QKeyEvent* ) ),
            this  , SLOT(slotKeyEvent ( QKeyEvent* ) ));
Jan Möbius's avatar
 
Jan Möbius committed
120
121
   _widget = tool_;
   QSize size(300, 300);
122
123
   tool_->resize(size);

Jan Möbius's avatar
 
Jan Möbius committed
124
   model_ = new TreeModel( );
125

126
   view_ = tool_->treeView;
127

128
   tool_->treeView->setModel(model_);
129

Jan Möbius's avatar
 
Jan Möbius committed
130
131
132
   view_->QTreeView::resizeColumnToContents(1);
   view_->QTreeView::resizeColumnToContents(2);
   view_->QTreeView::resizeColumnToContents(3);
133

Dirk Wilden's avatar
Dirk Wilden committed
134

Dirk Wilden's avatar
Dirk Wilden committed
135
136
   connect( model_,SIGNAL(dataChangedInside(int,int,const QVariant&) ),
            this,  SLOT(    slotDataChanged(int,int,const QVariant&)) );
137

Dirk Wilden's avatar
Dirk Wilden committed
138
139
   connect( model_,SIGNAL(   moveBaseObject(int,int) ),
            this,  SLOT( slotMoveBaseObject(int,int) ) );
140

Jan Möbius's avatar
 
Jan Möbius committed
141
142
   connect( view_,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
            this,SLOT(slotCustomContextMenuRequested ( const QPoint & ) ));
143

144
145
146
147
148
149
   connect( tool_->notSelected, SIGNAL(stateChanged ( int ) ),
            this, SLOT (slotBoundingBoxChange ( ) ));
   connect( tool_->sourceSelected, SIGNAL(stateChanged ( int ) ),
            this, SLOT (slotBoundingBoxChange ( ) ));
   connect( tool_->targetSelected, SIGNAL(stateChanged ( int ) ),
            this, SLOT (slotBoundingBoxChange ( ) ));
150

151

152
   viewHeader_ = tool_->treeView->header();
Jan Möbius's avatar
 
Jan Möbius committed
153
   viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
154

Jan Möbius's avatar
 
Jan Möbius committed
155
156
157
   // connect the slot for the context menu
   connect( viewHeader_, SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
            this,        SLOT(slotHeaderCustomContextMenuRequested ( const QPoint & ) ));
158

Jan Möbius's avatar
 
Jan Möbius committed
159
160
161
162
   return true;
}


Dirk Wilden's avatar
Dirk Wilden committed
163
//******************************************************************************
Jan Möbius's avatar
 
Jan Möbius committed
164

Dirk Wilden's avatar
Dirk Wilden committed
165
/** \brief update drawing of objects when the active object changed
166
 *
Dirk Wilden's avatar
Dirk Wilden committed
167
168
169
170
171
172
 */
void DataControlPlugin::slotObjectSelectionChanged( int _identifier )
{

  BaseObjectData* obj = 0;

173
  if ( PluginFunctions::getObject( _identifier, obj) )
174
175
    updateBoundingBox (obj);

Dirk Wilden's avatar
Dirk Wilden committed
176
177
  model_->objectChanged( _identifier );

Dirk Wilden's avatar
Dirk Wilden committed
178
179
180
181
182
183
184
185
186
187
  //check for changes in the tree
  BaseObject* object = 0;

  if ( PluginFunctions::getObject( _identifier, object) ){
    propagateUpwards(object->parent(), 2); // 2 = source-target

    if ( object->isGroup() )
      propagateDownwards(object, 2); // 2 = source-target
  }

Dirk Wilden's avatar
Dirk Wilden committed
188
189
190
191
192
193
194
  emit updateView();
}


//******************************************************************************

/** \brief Update the model if the visibility of an object changed
195
 *
Dirk Wilden's avatar
Dirk Wilden committed
196
197
 * @param _identifier id of an object
 */
Dirk Wilden's avatar
Dirk Wilden committed
198
void DataControlPlugin::slotVisibilityChanged( int _identifier ){
Dirk Wilden's avatar
Dirk Wilden committed
199
  //inform the model
Dirk Wilden's avatar
Dirk Wilden committed
200
  model_->objectChanged( _identifier );
Dirk Wilden's avatar
Dirk Wilden committed
201
202
203
204
205
206
207
208
209
210
211

  //check for changes in the tree
  BaseObject* obj = 0;

  if ( PluginFunctions::getObject( _identifier, obj) ){
    propagateUpwards(obj->parent(), 1); // 1 = visibilty

    if ( obj->isGroup() )
      propagateDownwards(obj, 1); // 1 = visibilty
  }

212
213
214
215
216
  BaseObjectData* object = 0;

  if ( PluginFunctions::getObject( _identifier, object) )
    updateBoundingBox (object);

Jan Möbius's avatar
 
Jan Möbius committed
217
218
219
}


Dirk Wilden's avatar
Dirk Wilden committed
220
//******************************************************************************
Jan Möbius's avatar
 
Jan Möbius committed
221

Dirk Wilden's avatar
Dirk Wilden committed
222
/** \brief Update the model if properties of an object changed
223
 *
Dirk Wilden's avatar
Dirk Wilden committed
224
 * @param _identifier id of an object
Dirk Wilden's avatar
Dirk Wilden committed
225
 */
Dirk Wilden's avatar
Dirk Wilden committed
226
227
228
void DataControlPlugin::slotObjectPropertiesChanged( int _identifier ){
  model_->objectChanged( _identifier );
}
Jan Möbius's avatar
 
Jan Möbius committed
229

Dirk Wilden's avatar
Dirk Wilden committed
230
231
232

//******************************************************************************

233
/** \brief Update the model if an object was deleted
234
 *
Dirk Wilden's avatar
Dirk Wilden committed
235
236
237
238
 * @param _identifier id of an object
 */
void DataControlPlugin::slotObjectUpdated( int _identifier ){

Dirk Wilden's avatar
Dirk Wilden committed
239
}
Dirk Wilden's avatar
Dirk Wilden committed
240

241

Dirk Wilden's avatar
Dirk Wilden committed
242
243
244
//******************************************************************************

/** \brief Update the model if a file has been opened
245
 *
Dirk Wilden's avatar
Dirk Wilden committed
246
247
 * @param _id id of an object
 */
Dirk Wilden's avatar
Dirk Wilden committed
248
249
250
251
252
253
void DataControlPlugin::fileOpened(int _id){

  BaseObject* obj = 0;

  if ( PluginFunctions::getObject(_id, obj) )
    model_->objectAdded(obj);
Dirk Wilden's avatar
Dirk Wilden committed
254
255
256
257
258
259
}


//******************************************************************************

/** \brief Update the model if an empty object has been added
260
 *
Dirk Wilden's avatar
Dirk Wilden committed
261
262
 * @param _id id of an object
 */
Dirk Wilden's avatar
Dirk Wilden committed
263
264
265
266
267
268
269
void DataControlPlugin::addedEmptyObject(int _id){
  fileOpened(_id);
}

//******************************************************************************

/** \brief an object was deleted. delete it internally
270
 *
Dirk Wilden's avatar
Dirk Wilden committed
271
272
273
274
 * @param _id id of the object
 */
void DataControlPlugin::objectDeleted(int _id){
  model_->objectDeleted(_id);
Jan Möbius's avatar
 
Jan Möbius committed
275
276
}

Dirk Wilden's avatar
Dirk Wilden committed
277
278
279
//******************************************************************************

/** \brief a key event occurred
280
 *
Dirk Wilden's avatar
Dirk Wilden committed
281
282
 * @param _event the event that occurred
 */
Jan Möbius's avatar
 
Jan Möbius committed
283
284
285
286
287
void DataControlPlugin::slotKeyEvent( QKeyEvent* _event )
{

  if ( _event->modifiers() == Qt::ControlModifier ) {
    switch (_event->key()) {
288
      case Qt::Key_A :
Jan Möbius's avatar
 
Jan Möbius committed
289
290
291
292
293
294
          setAllTarget();
        return;
      default:
        return;
    }
  }
295

296
297
298
299
300
301
302
  switch (_event->key()) {
    case Qt::Key_Delete :
        slotPopupRemove();
      return;
    default:
      return;
  }
303

Jan Möbius's avatar
 
Jan Möbius committed
304
305
}

Dirk Wilden's avatar
Dirk Wilden committed
306
307
308
309

//******************************************************************************

/** \brief emit the right updates when the model changed
310
 *
Dirk Wilden's avatar
Dirk Wilden committed
311
 * @param topLeft index in the model
Dirk Wilden's avatar
Dirk Wilden committed
312
 * @param _column hmm
Dirk Wilden's avatar
Dirk Wilden committed
313
 */
Dirk Wilden's avatar
Dirk Wilden committed
314
void DataControlPlugin::slotDataChanged ( int _id, int _column, const QVariant& _value)
Jan Möbius's avatar
 
Jan Möbius committed
315
{
316

Dirk Wilden's avatar
Dirk Wilden committed
317
318
319
320
  //get the corresponding baseObject
  BaseObject* obj = 0;
  if ( !PluginFunctions::getObject( _id, obj) )
    return;
Dirk Wilden's avatar
Dirk Wilden committed
321

Dirk Wilden's avatar
Dirk Wilden committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
  switch ( _column ) {
    // Name
    case 0:
      obj->setName( _value.toString() );
      emit objectPropertiesChanged( obj->id() );
      break;

    // show/hide
    case 1:
      obj->visible( _value.toBool() );
      emit visibilityChanged( obj->id() );
      break;

    // source
    case 2:
      obj->source( _value.toBool() );
      emit objectSelectionChanged( obj->id() );
      break;

    // target
    case 3:
      obj->target( _value.toBool() );
      emit objectSelectionChanged( obj->id() );
      break;
Dirk Wilden's avatar
Dirk Wilden committed
346

Dirk Wilden's avatar
Dirk Wilden committed
347
348
    default:
      break;
Jan Möbius's avatar
 
Jan Möbius committed
349
350
351
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
352
353
354

//******************************************************************************

Dirk Wilden's avatar
Dirk Wilden committed
355
/** \brief Gets called when an object was moved via drag n drop
356
 *
Dirk Wilden's avatar
Dirk Wilden committed
357
358
 * @param _id id of the object
 * @param _parentId id of the new parent
Dirk Wilden's avatar
Dirk Wilden committed
359
 */
Dirk Wilden's avatar
Dirk Wilden committed
360
void DataControlPlugin::slotMoveBaseObject(int _id, int _newParentId){
Dirk Wilden's avatar
Dirk Wilden committed
361

Dirk Wilden's avatar
Dirk Wilden committed
362
  BaseObject* obj = 0;
Dirk Wilden's avatar
Dirk Wilden committed
363

Dirk Wilden's avatar
Dirk Wilden committed
364
365
  if ( !PluginFunctions::getObject(_id, obj) )
    return;
Jan Möbius's avatar
 
Jan Möbius committed
366

Dirk Wilden's avatar
Dirk Wilden committed
367
  BaseObject* parent = 0;
Dirk Wilden's avatar
Dirk Wilden committed
368

Dirk Wilden's avatar
Dirk Wilden committed
369
370
  if ( !PluginFunctions::getObject(_newParentId, parent) )
    return;
Dirk Wilden's avatar
Dirk Wilden committed
371

Dirk Wilden's avatar
Dirk Wilden committed
372
  BaseObject* oldParent = obj->parent();
Dirk Wilden's avatar
Dirk Wilden committed
373

Dirk Wilden's avatar
Dirk Wilden committed
374
375
  //remove from old parent
  oldParent->removeChild( obj );
Dirk Wilden's avatar
Dirk Wilden committed
376

Dirk Wilden's avatar
Dirk Wilden committed
377
378
379
  //set new parent
  obj->setParent( parent );
  parent->appendChild( obj );
Dirk Wilden's avatar
Dirk Wilden committed
380

Dirk Wilden's avatar
Dirk Wilden committed
381
382
  // and inform everyone that the parent changed
  emit objectPropertiesChanged( _id );
Dirk Wilden's avatar
Dirk Wilden committed
383

Dirk Wilden's avatar
Dirk Wilden committed
384
385
386
  //if oldParent is an empty group -> delete it
  if ( oldParent != PluginFunctions::objectRoot() && oldParent->childCount() == 0 )
    emit deleteObject( oldParent->id() );
Dirk Wilden's avatar
Dirk Wilden committed
387
388
389
390
391
392
}


//******************************************************************************

/** \brief Load Groups from ini file
393
 *
Dirk Wilden's avatar
Dirk Wilden committed
394
395
 * @param _ini an ini file
 */
Jan Möbius's avatar
   
Jan Möbius committed
396
void DataControlPlugin::loadIniFileOptionsLast( INIFile& _ini ) {
397
398
399
400
401
402
403
404
405
406
407
408

  if ( _ini.section_exists( "BoundingBox" ) )
  {
    bool value;
    if (_ini.get_entry(value, "BoundingBox","notSelected"))
      tool_->notSelected->setChecked (value);
    if (_ini.get_entry(value, "BoundingBox","sourceSelected"))
      tool_->sourceSelected->setChecked (value);
    if (_ini.get_entry(value, "BoundingBox","targetSelected"))
      tool_->targetSelected->setChecked (value);
  }

409
  if ( !_ini.section_exists( "Groups" ) )
Jan Möbius's avatar
 
Jan Möbius committed
410
    return;
411

Jan Möbius's avatar
 
Jan Möbius committed
412
413
  // Names of all groups
  QStringList groupNames;
414

Jan Möbius's avatar
 
Jan Möbius committed
415
416
  // names of the primary groups
  QStringList rootGroup;
417

Jan Möbius's avatar
 
Jan Möbius committed
418
419
  // Get the list of group names to the file
  _ini.get_entry(groupNames,"Groups","groups");
420

Jan Möbius's avatar
 
Jan Möbius committed
421
422
  // Get the primary group names to the file
  _ini.get_entry(rootGroup,"Groups","rootGroup");
423

Dirk Wilden's avatar
Dirk Wilden committed
424
425
426
  //list of groups
  QVector< BaseObject* > groups;

Jan Möbius's avatar
 
Jan Möbius committed
427
428
429
430
  // Go over one level of the groups
  while ( rootGroup.size() > 0 ) {
    QString current = rootGroup[0];
    rootGroup.removeFirst();
431

Jan Möbius's avatar
 
Jan Möbius committed
432
433
    QStringList groupChildren;
    QStringList elementChildren;
434

Jan Möbius's avatar
 
Jan Möbius committed
435
436
    _ini.get_entry(elementChildren ,current,"children");
    _ini.get_entry(groupChildren ,current,"subgroups");
437

Jan Möbius's avatar
 
Jan Möbius committed
438
439
440
441
442
443
    // if we get a parent item, scan the tree for it or use the root node otherwise
    BaseObject* parentItem;
    QString parentName;
    if ( _ini.get_entry(parentName,current,"parent") ) {
      parentItem = PluginFunctions::objectRoot()->childExists(parentName);
      if ( parentItem == 0 )
444
445
446
447
448
449
        parentItem = PluginFunctions::objectRoot();
    } else
      parentItem = PluginFunctions::objectRoot();

    rootGroup << groupChildren;

Jan Möbius's avatar
 
Jan Möbius committed
450
451
    // check if this group already exists
    BaseObject* group =  PluginFunctions::objectRoot()->childExists( current );
452

Jan Möbius's avatar
 
Jan Möbius committed
453
454
    // group does not exist
    if ( !group ) {
455

Jan Möbius's avatar
 
Jan Möbius committed
456
      group = dynamic_cast< BaseObject* >( new GroupObject( current, dynamic_cast< GroupObject* >(parentItem ) ) );
457

Jan Möbius's avatar
 
Jan Möbius committed
458
459
      parentItem->appendChild(group);
      group->setParent(parentItem);
Dirk Wilden's avatar
Dirk Wilden committed
460
461
462
463
464
465
466
467
468
469

      emit emptyObjectAdded( group->id() );

      // in the groups vector we only need the lowest groups
      // because they are used recursively
      int p = groups.indexOf( group->parent() );
      if ( p > -1 )
        groups.remove( p );

      groups.push_back( group );
Jan Möbius's avatar
 
Jan Möbius committed
470
    }
471

Jan Möbius's avatar
 
Jan Möbius committed
472
473
474
475
476
477
478
    // process children
    for ( int i = 0 ; i < elementChildren.size() ; ++i ) {
      BaseObject* childItem =  PluginFunctions::objectRoot()->childExists( elementChildren[i] );
      if ( childItem ) {
        childItem->parent()->removeChild(childItem);
        childItem->setParent(group);
        group->appendChild(childItem);
Dirk Wilden's avatar
Dirk Wilden committed
479
480
481

        //inform everyone that the parent changed
        emit objectPropertiesChanged( childItem->id() );
Jan Möbius's avatar
 
Jan Möbius committed
482
483
484
      }
    }
  }
485

Dirk Wilden's avatar
Dirk Wilden committed
486
487
488
489
  for (int i=0; i < groups.count(); i++){
    propagateUpwards( groups[i], 1);
    propagateUpwards( groups[i], 2);
  }
Jan Möbius's avatar
 
Jan Möbius committed
490
491
}

Dirk Wilden's avatar
Dirk Wilden committed
492
493
494
495

//******************************************************************************

/** \brief Save groups to ini file
496
 *
Dirk Wilden's avatar
Dirk Wilden committed
497
498
 * @param _ini an ini file
 */
Jan Möbius's avatar
 
Jan Möbius committed
499
void DataControlPlugin::saveIniFileOptions( INIFile& _ini ) {
500

501
502
503
  if ( !_ini.section_exists( "Groups" ) )
    _ini.add_section("Groups");

Jan Möbius's avatar
 
Jan Möbius committed
504
505
  std::queue< BaseObject* > children;
  children.push( PluginFunctions::objectRoot() );
506

Jan Möbius's avatar
 
Jan Möbius committed
507
  std::vector< BaseObject* > groups;
508

Jan Möbius's avatar
 
Jan Möbius committed
509
510
511
512
  // Get all groups from the tree
  while ( children.size() > 0 ) {
    BaseObject* item = children.front();
    children.pop();
513
514
515
516
517

    for ( int i = 0 ; i < item->childCount(); ++i )
      if ( item->child(i)->dataType(DATA_GROUP))
        children.push( item->child(i) );

Jan Möbius's avatar
 
Jan Möbius committed
518
519
520
    if ( item->dataType(DATA_GROUP) && (item != PluginFunctions::objectRoot() ) )
      groups.push_back(item);
  }
521

Jan Möbius's avatar
 
Jan Möbius committed
522
523
  // Names of all groups
  QStringList groupNames;
524

Jan Möbius's avatar
 
Jan Möbius committed
525
526
  // names of the primary groups
  QStringList rootGroup;
527

Jan Möbius's avatar
 
Jan Möbius committed
528
  for ( uint i = 0 ; i < groups.size() ; ++i ) {
529
530
531
532
533
    groupNames.push_back( groups[i]->name() );

    if ( !_ini.section_exists( groups[i]->name() ) )
      _ini.add_section(groups[i]->name());

Jan Möbius's avatar
 
Jan Möbius committed
534
    _ini.add_entry(groups[i]->name(),"groupname",groups[i]->name());
535
536

    // write the name of the parent
Jan Möbius's avatar
 
Jan Möbius committed
537
538
    if ( ( groups[i]->parent() != 0 ) && ( groups[i]->parent() != PluginFunctions::objectRoot() ) )
      _ini.add_entry(groups[i]->name(),"parent",groups[i]->parent()->name());
539

Jan Möbius's avatar
 
Jan Möbius committed
540
541
    if ( groups[i]->parent() == PluginFunctions::objectRoot() )
      rootGroup.push_back( groups[i]->name() );
542

Jan Möbius's avatar
 
Jan Möbius committed
543
544
545
546
547
548
549
550
551
    // Write a list of this groups children
    QStringList groupchildren;
    QStringList elementchildren;
    for ( int j = 0 ; j < groups[i]->childCount(); ++j ) {
      if  ( groups[i]->child(j)->dataType(DATA_GROUP) )
        groupchildren.push_back( groups[i]->child(j)->name() );
      else
        elementchildren.push_back( groups[i]->child(j)->name() );
    }
552

Jan Möbius's avatar
 
Jan Möbius committed
553
554
555
    _ini.add_entry(groups[i]->name(),"subgroups",groupchildren);
    _ini.add_entry(groups[i]->name(),"children",elementchildren);
  }
556

Jan Möbius's avatar
 
Jan Möbius committed
557
558
  // Write the list of group names to the file
  _ini.add_entry("Groups","groups",groupNames);
559

Jan Möbius's avatar
 
Jan Möbius committed
560
561
  // Write the primary group names to the file
  _ini.add_entry("Groups","rootGroup",rootGroup);
562
563
564
565
566
567
568

  if ( !_ini.section_exists( "BoundingBox" ) )
    _ini.add_section("BoundingBox");
  _ini.add_entry("BoundingBox","notSelected",tool_->notSelected->isChecked ());
  _ini.add_entry("BoundingBox","sourceSelected",tool_->sourceSelected->isChecked ());
  _ini.add_entry("BoundingBox","targetSelected",tool_->targetSelected->isChecked ());

Jan Möbius's avatar
 
Jan Möbius committed
569
570
571
}


Dirk Wilden's avatar
Dirk Wilden committed
572
573
574
//******************************************************************************

/** \brief Recursively update a column up to the root of the tree
575
 *
Dirk Wilden's avatar
Dirk Wilden committed
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
 * @param _obj object to start with
 */
void DataControlPlugin::propagateUpwards(BaseObject* _obj, int _column ){

  if ( _obj == PluginFunctions::objectRoot() || (!_obj->isGroup()) )
    return;

  QList< BaseObject* > children = _obj->getLeafs();
  bool changed = false;
  bool value    = false;
  bool value2   = false;


  switch ( _column ){

    case 1: //VISIBILTY

      for (int i=0; i < children.size(); i++)
        value |= children[i]->visible();

      _obj->visible( value );

      changed = true;

      break;

    case 2: //SOURCE-TARGET

      for (int i=0; i < children.size(); i++){
        value  |= children[i]->source();
        value2 |= children[i]->target();
      }

      if (_obj->source() != value){
        _obj->source( value );
        changed = true;
      }

      if (_obj->target() != value2){
        _obj->target( value2 );
        changed = true;
      }

      break;

    default:
      break;
  }

  if ( changed )
    propagateUpwards( _obj->parent(), _column );
}

//******************************************************************************

/** \brief Recursively update a column up to the root of the tree
632
 *
Dirk Wilden's avatar
Dirk Wilden committed
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
 * @param _obj object to start with
 */
void DataControlPlugin::propagateDownwards(BaseObject* _obj, int _column ){

  for (int i=0; i < _obj->childCount(); i++){

    BaseObject* current = _obj->child(i);

    bool changed = false;

    switch ( _column ){

      case 1: //VISIBILTY

        if ( current->visible() != _obj->visible() ){

          current->visible( _obj->visible() );

          changed = true;
        }
        break;

      case 2: //SOURCE-TARGET

        if ( current->source() != _obj->source() ){
          current->source( _obj->source() );
          changed = true;
        }

        if ( current->target() != _obj->target() ){
          current->target( _obj->target() );
          changed = true;
        }

        break;

      default:
        break;
    }

    if ( changed && current->isGroup() ){
      propagateDownwards(current, _column);

    }
  }
}

680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
//******************************************************************************

/** \brief Bounding box visibility selection changed
 */
void DataControlPlugin::slotBoundingBoxChange( )
{
  for (PluginFunctions::ObjectIterator o_it; o_it != PluginFunctions::objectsEnd(); ++o_it)  {
    updateBoundingBox (o_it);
  }

  emit updateView();
}

//******************************************************************************

/** \brief Update state of bounding box node
 *
 * @param _obj object
 */
void DataControlPlugin::updateBoundingBox(BaseObjectData* _obj)
{
  if (tool_->notSelected->isChecked () ||
      (_obj->source () && tool_->sourceSelected->isChecked ()) ||
      (_obj->target () && tool_->targetSelected->isChecked ()))
  {
    _obj->boundingBoxNode()->set_status( ACG::SceneGraph::BaseNode::Active );

    ACG::Vec4f color = base_color;

    if (_obj->source () && tool_->sourceSelected->isChecked ())
      color += source_color;

    if (_obj->target () && tool_->targetSelected->isChecked ())
      color += target_color;

    _obj->boundingBoxNode()->set_base_color (color);
  }
  else
    _obj->boundingBoxNode()->set_status( ACG::SceneGraph::TranslationManipulatorNode::HideNode );

}

//******************************************************************************
/** \brief Save settings before application is closed
 *
 * @param _ini reference to ini file
 */
void DataControlPlugin::saveOnExit(INIFile& _ini){
728
729
730
731
732
  if ( !_ini.section_exists( "BoundingBox" ) )
    _ini.add_section("BoundingBox");
  _ini.add_entry("BoundingBox","notSelected",tool_->notSelected->isChecked ());
  _ini.add_entry("BoundingBox","sourceSelected",tool_->sourceSelected->isChecked ());
  _ini.add_entry("BoundingBox","targetSelected",tool_->targetSelected->isChecked ());
733
734
}

Dirk Wilden's avatar
Dirk Wilden committed
735

Jan Möbius's avatar
 
Jan Möbius committed
736
737
Q_EXPORT_PLUGIN2( datacontrolplugin , DataControlPlugin );