DataControlPlugin.cc 21.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  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 with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  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.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
 *   $Revision$                                                       *
38
39
40
41
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51





#include <QtGui>

#include "DataControlPlugin.hh"

#include <QLayout>
52
#include <QGridLayout>
Jan Möbius's avatar
 
Jan Möbius committed
53
#include <QItemSelectionModel>
54

Jan Möbius's avatar
 
Jan Möbius committed
55
56
57
58
#include <iostream>
#include <ACG/GL/GLState.hh>
#include <QStringList>
#include <ACG/Scenegraph/BaseNode.hh>
Dirk Wilden's avatar
Dirk Wilden committed
59
#include <ACG/QtWidgets/QtMaterialDialog.hh>
Jan Möbius's avatar
 
Jan Möbius committed
60
61
62
63
64
#include <QModelIndexList>

#include <queue>

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

Dirk Wilden's avatar
Dirk Wilden committed
67
//******************************************************************************
Dirk Wilden's avatar
Dirk Wilden committed
68

69
70
71
72
73
74
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
75
/** \brief Plugin initialization
76
 *
Dirk Wilden's avatar
Dirk Wilden committed
77
 */
Jan Möbius's avatar
 
Jan Möbius committed
78
void DataControlPlugin::pluginsInitialized() {
79

Jan Möbius's avatar
   
Jan Möbius committed
80
81
82
  //set the slot descriptions
  setDescriptions();

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

Jan Möbius's avatar
 
Jan Möbius committed
85
86
87
88
89
  //Target Objects
  QAction* hideAction = new QAction(tr("&Hide"), this);
  hideAction->setStatusTip(tr("Hide object"));
  connect(hideAction, SIGNAL(triggered()), this, SLOT(slotContextMenuHide()) );
  contextMenu->addAction(hideAction);
90

Jan Möbius's avatar
 
Jan Möbius committed
91
92
93
94
95
96
  //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_);
97

Jan Möbius's avatar
 
Jan Möbius committed
98
99
100
101
102
  //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()) );
103
104
  contextMenu->addAction(sourceAction_);

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

107
  QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-material.png");
Jan Möbius's avatar
Jan Möbius committed
108
  QAction* material = new QAction(icon, tr("Material Properties"), 0);
109
110
111
  connect (material, SIGNAL( triggered() ), this, SLOT ( slotMaterialProperties() ));

  emit addContextMenuItem(material , DATA_ALL , CONTEXTOBJECTMENU);
112
113
114

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

Dirk Wilden's avatar
Dirk Wilden committed
117
118
119

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

120
void DataControlPlugin::initializePlugin()
Jan Möbius's avatar
 
Jan Möbius committed
121
122
{
   locked = false;
123
124
125
   tool_ = new DatacontrolToolboxWidget();
   connect( tool_ , SIGNAL( keyEvent( QKeyEvent* ) ),
            this  , SLOT(slotKeyEvent ( QKeyEvent* ) ));
Jan Möbius's avatar
 
Jan Möbius committed
126
   QSize size(300, 300);
127
128
   tool_->resize(size);

Jan Möbius's avatar
 
Jan Möbius committed
129
   model_ = new TreeModel( );
130

131
   view_ = tool_->treeView;
132

133
   tool_->treeView->setModel(model_);
134

Jan Möbius's avatar
 
Jan Möbius committed
135
136
137
   view_->QTreeView::resizeColumnToContents(1);
   view_->QTreeView::resizeColumnToContents(2);
   view_->QTreeView::resizeColumnToContents(3);
138

Dirk Wilden's avatar
Dirk Wilden committed
139

Dirk Wilden's avatar
Dirk Wilden committed
140
141
   connect( model_,SIGNAL(dataChangedInside(int,int,const QVariant&) ),
            this,  SLOT(    slotDataChanged(int,int,const QVariant&)) );
142

Dirk Wilden's avatar
Dirk Wilden committed
143
144
   connect( model_,SIGNAL(   moveBaseObject(int,int) ),
            this,  SLOT( slotMoveBaseObject(int,int) ) );
145

Jan Möbius's avatar
 
Jan Möbius committed
146
147
   connect( view_,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
            this,SLOT(slotCustomContextMenuRequested ( const QPoint & ) ));
148

149
150
151
152
153
154
   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 ( ) ));
155

156

157
   viewHeader_ = tool_->treeView->header();
Jan Möbius's avatar
 
Jan Möbius committed
158
   viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
159

Jan Möbius's avatar
 
Jan Möbius committed
160
161
162
   // connect the slot for the context menu
   connect( viewHeader_, SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
            this,        SLOT(slotHeaderCustomContextMenuRequested ( const QPoint & ) ));
163

164
   emit addToolbox("Data Control", tool_);
Jan Möbius's avatar
 
Jan Möbius committed
165
166
167
}


Dirk Wilden's avatar
Dirk Wilden committed
168
//******************************************************************************
Jan Möbius's avatar
 
Jan Möbius committed
169

Dirk Wilden's avatar
Dirk Wilden committed
170
/** \brief update drawing of objects when the active object changed
171
 *
Dirk Wilden's avatar
Dirk Wilden committed
172
173
174
175
176
177
 */
void DataControlPlugin::slotObjectSelectionChanged( int _identifier )
{

  BaseObjectData* obj = 0;

178
  if ( PluginFunctions::getObject( _identifier, obj) )
179
180
    updateBoundingBox (obj);

Dirk Wilden's avatar
Dirk Wilden committed
181
182
  model_->objectChanged( _identifier );

Dirk Wilden's avatar
Dirk Wilden committed
183
184
185
186
187
188
189
190
191
192
  //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
193
194
195
196
197
198
199
  emit updateView();
}


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

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

  //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
  }

217
218
219
220
221
  BaseObjectData* object = 0;

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

Jan Möbius's avatar
 
Jan Möbius committed
222
223
224
}


Dirk Wilden's avatar
Dirk Wilden committed
225
//******************************************************************************
Jan Möbius's avatar
 
Jan Möbius committed
226

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

Dirk Wilden's avatar
Dirk Wilden committed
235
236
237

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

238
/** \brief Update the model if an object was deleted
239
 *
Dirk Wilden's avatar
Dirk Wilden committed
240
241
242
243
 * @param _identifier id of an object
 */
void DataControlPlugin::slotObjectUpdated( int _identifier ){

Dirk Wilden's avatar
Dirk Wilden committed
244
}
Dirk Wilden's avatar
Dirk Wilden committed
245

246

Dirk Wilden's avatar
Dirk Wilden committed
247
248
249
//******************************************************************************

/** \brief Update the model if a file has been opened
250
 *
Dirk Wilden's avatar
Dirk Wilden committed
251
252
 * @param _id id of an object
 */
Dirk Wilden's avatar
Dirk Wilden committed
253
254
255
256
257
258
void DataControlPlugin::fileOpened(int _id){

  BaseObject* obj = 0;

  if ( PluginFunctions::getObject(_id, obj) )
    model_->objectAdded(obj);
Dirk Wilden's avatar
Dirk Wilden committed
259
260
261
262
263
264
}


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

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

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

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

Dirk Wilden's avatar
Dirk Wilden committed
282
283
284
//******************************************************************************

/** \brief a key event occurred
285
 *
Dirk Wilden's avatar
Dirk Wilden committed
286
287
 * @param _event the event that occurred
 */
Jan Möbius's avatar
 
Jan Möbius committed
288
289
290
291
292
void DataControlPlugin::slotKeyEvent( QKeyEvent* _event )
{

  if ( _event->modifiers() == Qt::ControlModifier ) {
    switch (_event->key()) {
293
      case Qt::Key_A :
Jan Möbius's avatar
 
Jan Möbius committed
294
295
296
297
298
299
          setAllTarget();
        return;
      default:
        return;
    }
  }
300

301
302
303
304
305
306
307
  switch (_event->key()) {
    case Qt::Key_Delete :
        slotPopupRemove();
      return;
    default:
      return;
  }
308

Jan Möbius's avatar
 
Jan Möbius committed
309
310
}

Dirk Wilden's avatar
Dirk Wilden committed
311
312
313
314

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

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

Dirk Wilden's avatar
Dirk Wilden committed
322
323
324
325
  //get the corresponding baseObject
  BaseObject* obj = 0;
  if ( !PluginFunctions::getObject( _id, obj) )
    return;
Dirk Wilden's avatar
Dirk Wilden committed
326

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

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

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

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

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

Dirk Wilden's avatar
Dirk Wilden committed
354
355
356

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

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

Dirk Wilden's avatar
Dirk Wilden committed
364
  BaseObject* obj = 0;
Dirk Wilden's avatar
Dirk Wilden committed
365

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

Dirk Wilden's avatar
Dirk Wilden committed
369
  BaseObject* parent = 0;
Dirk Wilden's avatar
Dirk Wilden committed
370

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

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

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

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

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

Dirk Wilden's avatar
Dirk Wilden committed
386
387
388
  //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
389
390
391
392
393
394
}


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

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

  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);
  }

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

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

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

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

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

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

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

Jan Möbius's avatar
 
Jan Möbius committed
434
435
    QStringList groupChildren;
    QStringList elementChildren;
436

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

Jan Möbius's avatar
 
Jan Möbius committed
440
441
442
443
444
445
    // 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 )
446
447
448
449
450
451
        parentItem = PluginFunctions::objectRoot();
    } else
      parentItem = PluginFunctions::objectRoot();

    rootGroup << groupChildren;

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

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

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

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

      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
472
    }
473

Jan Möbius's avatar
 
Jan Möbius committed
474
475
476
477
478
479
480
    // 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
481
482
483

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

Dirk Wilden's avatar
Dirk Wilden committed
488
489
490
491
  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
492
493
}

Dirk Wilden's avatar
Dirk Wilden committed
494
495
496
497

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

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

503
504
505
  if ( !_ini.section_exists( "Groups" ) )
    _ini.add_section("Groups");

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

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

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

    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
520
521
522
    if ( item->dataType(DATA_GROUP) && (item != PluginFunctions::objectRoot() ) )
      groups.push_back(item);
  }
523

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

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

Jan Möbius's avatar
 
Jan Möbius committed
530
  for ( uint i = 0 ; i < groups.size() ; ++i ) {
531
532
533
534
535
    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
536
    _ini.add_entry(groups[i]->name(),"groupname",groups[i]->name());
537
538

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

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

Jan Möbius's avatar
 
Jan Möbius committed
545
546
547
548
549
550
551
552
553
    // 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() );
    }
554

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

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

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

  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
571
572
573
}


Dirk Wilden's avatar
Dirk Wilden committed
574
575
576
//******************************************************************************

/** \brief Recursively update a column up to the root of the tree
577
 *
Dirk Wilden's avatar
Dirk Wilden committed
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
632
633
 * @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
634
 *
Dirk Wilden's avatar
Dirk Wilden committed
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
680
681
 * @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);

    }
  }
}

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
728
729
//******************************************************************************

/** \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){
730
731
732
733
734
  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 ());
735
736
}

Dirk Wilden's avatar
Dirk Wilden committed
737

Jan Möbius's avatar
 
Jan Möbius committed
738
739
Q_EXPORT_PLUGIN2( datacontrolplugin , DataControlPlugin );