DataControlPlugin.cc 22.3 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();

Dirk Wilden's avatar
 
Dirk Wilden committed
83
  QMenu* contextMenu = new QMenu("Object");
84

Jan Möbius's avatar
 
Jan Möbius committed
85
  //Target Objects
Dirk Wilden's avatar
 
Dirk Wilden committed
86 87
  QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-hide-object.png");
  QAction* hideAction = new QAction(icon, tr("&Hide"), this);
Jan Möbius's avatar
 
Jan Möbius committed
88 89 90
  hideAction->setStatusTip(tr("Hide object"));
  connect(hideAction, SIGNAL(triggered()), this, SLOT(slotContextMenuHide()) );
  contextMenu->addAction(hideAction);
91

Jan Möbius's avatar
 
Jan Möbius committed
92
  //Target Objects
Dirk Wilden's avatar
 
Dirk Wilden committed
93 94
  icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-target-object.png");
  targetAction_ = new QAction(icon, tr("&Target"), this);
Jan Möbius's avatar
 
Jan Möbius committed
95 96 97 98
  targetAction_->setCheckable(true);
  targetAction_->setStatusTip(tr("Set object as target"));
  connect(targetAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuTarget()) );
  contextMenu->addAction(targetAction_);
99

Jan Möbius's avatar
 
Jan Möbius committed
100
  //Source Objects
Dirk Wilden's avatar
 
Dirk Wilden committed
101 102
  icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-source-object.png");
  sourceAction_ = new QAction(icon, tr("&Source"), this);
Jan Möbius's avatar
 
Jan Möbius committed
103 104 105
  sourceAction_->setCheckable(true);
  sourceAction_->setStatusTip(tr("Set object as source"));
  connect(sourceAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuSource()) );
106 107
  contextMenu->addAction(sourceAction_);

Dirk Wilden's avatar
 
Dirk Wilden committed
108 109 110 111 112 113 114 115 116 117
  contextMenu->addSeparator();
  
  //Remove Objects
  icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-delete-item.png");
  removeAction_ = new QAction(icon, tr("&Remove"), this);
  removeAction_->setCheckable(false);
  removeAction_->setStatusTip(tr("Remove object"));
  connect(removeAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuRemove()) );
  contextMenu->addAction(removeAction_);
  
Jan Möbius's avatar
 
Jan Möbius committed
118
  emit addContextMenuItem(contextMenu->menuAction() , DATA_ALL , CONTEXTOBJECTMENU);
119

Dirk Wilden's avatar
 
Dirk Wilden committed
120
  icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-material.png");
Jan Möbius's avatar
Jan Möbius committed
121
  QAction* material = new QAction(icon, tr("Material Properties"), 0);
122 123 124
  connect (material, SIGNAL( triggered() ), this, SLOT ( slotMaterialProperties() ));

  emit addContextMenuItem(material , DATA_ALL , CONTEXTOBJECTMENU);
125 126 127

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

Dirk Wilden's avatar
Dirk Wilden committed
130 131 132

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

133
void DataControlPlugin::initializePlugin()
Jan Möbius's avatar
 
Jan Möbius committed
134 135
{
   locked = false;
136 137 138
   tool_ = new DatacontrolToolboxWidget();
   connect( tool_ , SIGNAL( keyEvent( QKeyEvent* ) ),
            this  , SLOT(slotKeyEvent ( QKeyEvent* ) ));
Jan Möbius's avatar
 
Jan Möbius committed
139
   QSize size(300, 300);
140 141
   tool_->resize(size);

Jan Möbius's avatar
 
Jan Möbius committed
142
   model_ = new TreeModel( );
143

144
   view_ = tool_->treeView;
145

146
   tool_->treeView->setModel(model_);
147

Jan Möbius's avatar
 
Jan Möbius committed
148 149 150
   view_->QTreeView::resizeColumnToContents(1);
   view_->QTreeView::resizeColumnToContents(2);
   view_->QTreeView::resizeColumnToContents(3);
151

Dirk Wilden's avatar
Dirk Wilden committed
152

Dirk Wilden's avatar
Dirk Wilden committed
153 154
   connect( model_,SIGNAL(dataChangedInside(int,int,const QVariant&) ),
            this,  SLOT(    slotDataChanged(int,int,const QVariant&)) );
155

Dirk Wilden's avatar
Dirk Wilden committed
156 157
   connect( model_,SIGNAL(   moveBaseObject(int,int) ),
            this,  SLOT( slotMoveBaseObject(int,int) ) );
158

Jan Möbius's avatar
 
Jan Möbius committed
159 160
   connect( view_,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
            this,SLOT(slotCustomContextMenuRequested ( const QPoint & ) ));
161

162 163 164 165 166 167
   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 ( ) ));
168

169

170
   viewHeader_ = tool_->treeView->header();
Jan Möbius's avatar
 
Jan Möbius committed
171
   viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
172

Jan Möbius's avatar
 
Jan Möbius committed
173 174 175
   // connect the slot for the context menu
   connect( viewHeader_, SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
            this,        SLOT(slotHeaderCustomContextMenuRequested ( const QPoint & ) ));
176

177
   emit addToolbox("Data Control", tool_);
178 179 180
   
   onlyDown_ = 0;
   onlyUp_   = 0;
Jan Möbius's avatar
 
Jan Möbius committed
181 182 183
}


Dirk Wilden's avatar
Dirk Wilden committed
184
//******************************************************************************
Jan Möbius's avatar
 
Jan Möbius committed
185

Dirk Wilden's avatar
Dirk Wilden committed
186
/** \brief update drawing of objects when the active object changed
187
 *
Dirk Wilden's avatar
Dirk Wilden committed
188 189 190
 */
void DataControlPlugin::slotObjectSelectionChanged( int _identifier )
{
191
  
Dirk Wilden's avatar
Dirk Wilden committed
192 193
  BaseObjectData* obj = 0;

194
  if ( PluginFunctions::getObject( _identifier, obj) )
195 196
    updateBoundingBox (obj);

197 198 199 200
  // if onlyUp_ > 0 --> _identifier is a group and the selection
  // does not have to be applied
  if (onlyUp_ == 0)
    model_->objectChanged( _identifier );
Dirk Wilden's avatar
Dirk Wilden committed
201

202
  
Dirk Wilden's avatar
Dirk Wilden committed
203 204 205 206
  //check for changes in the tree
  BaseObject* object = 0;

  if ( PluginFunctions::getObject( _identifier, object) ){
207 208 209 210 211 212 213 214 215 216 217 218 219
    
      // if we are allowed to propagate up
      if ( onlyDown_ == 0 ){
  
        onlyUp_++;
    
        propagateUpwards(object->parent(), 2); // 2 = source-target

        onlyUp_--;
      }
    
      // if we are allowed to propagate down
      if ( onlyUp_ == 0 ){
Dirk Wilden's avatar
Dirk Wilden committed
220

221
        onlyDown_++;
Dirk Wilden's avatar
Dirk Wilden committed
222

223 224 225 226 227 228
        if ( object->isGroup() )
          propagateDownwards(object, 2); // 2 = source-target
      
        onlyDown_--;
      }
  }
Dirk Wilden's avatar
Dirk Wilden committed
229 230 231 232 233 234
}


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

/** \brief Update the model if the visibility of an object changed
235
 *
Dirk Wilden's avatar
Dirk Wilden committed
236 237
 * @param _identifier id of an object
 */
Dirk Wilden's avatar
Dirk Wilden committed
238
void DataControlPlugin::slotVisibilityChanged( int _identifier ){
239 240 241 242 243 244 245

  // if onlyUp_ > 0 --> _identifier is a group and the selection
  // does not have to be applied
  if (onlyUp_ == 0){
    //inform the model
    model_->objectChanged( _identifier );
  }
Dirk Wilden's avatar
Dirk Wilden committed
246 247 248 249 250 251

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

  if ( PluginFunctions::getObject( _identifier, obj) ){

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
    // if we are allowed to propagate up
    if ( onlyDown_ == 0 ){
    
      onlyUp_++;

      propagateUpwards(obj->parent(), 1); // 1 = visibilty

      onlyUp_--;  

    }

    // if we are allowed to propagate down
    if ( onlyUp_ == 0 ){

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

      onlyDown_--;
    }
Dirk Wilden's avatar
Dirk Wilden committed
273 274
  }

275 276 277 278 279
  BaseObjectData* object = 0;

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

Jan Möbius's avatar
 
Jan Möbius committed
280 281 282
}


Dirk Wilden's avatar
Dirk Wilden committed
283
//******************************************************************************
Jan Möbius's avatar
 
Jan Möbius committed
284

Dirk Wilden's avatar
Dirk Wilden committed
285
/** \brief Update the model if properties of an object changed
286
 *
Dirk Wilden's avatar
Dirk Wilden committed
287
 * @param _identifier id of an object
Dirk Wilden's avatar
Dirk Wilden committed
288
 */
Dirk Wilden's avatar
Dirk Wilden committed
289 290 291
void DataControlPlugin::slotObjectPropertiesChanged( int _identifier ){
  model_->objectChanged( _identifier );
}
Jan Möbius's avatar
 
Jan Möbius committed
292

Dirk Wilden's avatar
Dirk Wilden committed
293 294 295

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

296
/** \brief Update the model if an object was deleted
297
 *
Dirk Wilden's avatar
Dirk Wilden committed
298 299 300 301
 * @param _identifier id of an object
 */
void DataControlPlugin::slotObjectUpdated( int _identifier ){

Dirk Wilden's avatar
Dirk Wilden committed
302
}
Dirk Wilden's avatar
Dirk Wilden committed
303

304

Dirk Wilden's avatar
Dirk Wilden committed
305 306 307
//******************************************************************************

/** \brief Update the model if a file has been opened
308
 *
Dirk Wilden's avatar
Dirk Wilden committed
309 310
 * @param _id id of an object
 */
Dirk Wilden's avatar
Dirk Wilden committed
311 312 313 314 315 316
void DataControlPlugin::fileOpened(int _id){

  BaseObject* obj = 0;

  if ( PluginFunctions::getObject(_id, obj) )
    model_->objectAdded(obj);
Dirk Wilden's avatar
Dirk Wilden committed
317 318 319 320 321 322
}


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

/** \brief Update the model if an empty object has been added
323
 *
Dirk Wilden's avatar
Dirk Wilden committed
324 325
 * @param _id id of an object
 */
Dirk Wilden's avatar
Dirk Wilden committed
326 327 328 329 330 331 332
void DataControlPlugin::addedEmptyObject(int _id){
  fileOpened(_id);
}

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

/** \brief an object was deleted. delete it internally
333
 *
Dirk Wilden's avatar
Dirk Wilden committed
334 335 336 337
 * @param _id id of the object
 */
void DataControlPlugin::objectDeleted(int _id){
  model_->objectDeleted(_id);
Jan Möbius's avatar
 
Jan Möbius committed
338 339
}

Dirk Wilden's avatar
Dirk Wilden committed
340 341 342
//******************************************************************************

/** \brief a key event occurred
343
 *
Dirk Wilden's avatar
Dirk Wilden committed
344 345
 * @param _event the event that occurred
 */
Jan Möbius's avatar
 
Jan Möbius committed
346 347 348 349 350
void DataControlPlugin::slotKeyEvent( QKeyEvent* _event )
{

  if ( _event->modifiers() == Qt::ControlModifier ) {
    switch (_event->key()) {
351
      case Qt::Key_A :
Jan Möbius's avatar
 
Jan Möbius committed
352 353 354 355 356 357
          setAllTarget();
        return;
      default:
        return;
    }
  }
358

359 360 361 362 363 364 365
  switch (_event->key()) {
    case Qt::Key_Delete :
        slotPopupRemove();
      return;
    default:
      return;
  }
366

Jan Möbius's avatar
 
Jan Möbius committed
367 368
}

Dirk Wilden's avatar
Dirk Wilden committed
369 370 371 372

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

/** \brief emit the right updates when the model changed
373
 *
Dirk Wilden's avatar
Dirk Wilden committed
374
 * @param topLeft index in the model
Dirk Wilden's avatar
Dirk Wilden committed
375
 * @param _column hmm
Dirk Wilden's avatar
Dirk Wilden committed
376
 */
Dirk Wilden's avatar
Dirk Wilden committed
377
void DataControlPlugin::slotDataChanged ( int _id, int _column, const QVariant& _value)
Jan Möbius's avatar
 
Jan Möbius committed
378
{
379

Dirk Wilden's avatar
Dirk Wilden committed
380 381 382 383
  //get the corresponding baseObject
  BaseObject* obj = 0;
  if ( !PluginFunctions::getObject( _id, obj) )
    return;
384
  
Dirk Wilden's avatar
Dirk Wilden committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
  switch ( _column ) {
    // Name
    case 0:
      obj->setName( _value.toString() );
      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
405

Dirk Wilden's avatar
Dirk Wilden committed
406 407
    default:
      break;
Jan Möbius's avatar
 
Jan Möbius committed
408 409 410
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
411 412 413

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

Dirk Wilden's avatar
Dirk Wilden committed
414
/** \brief Gets called when an object was moved via drag n drop
415
 *
Dirk Wilden's avatar
Dirk Wilden committed
416 417
 * @param _id id of the object
 * @param _parentId id of the new parent
Dirk Wilden's avatar
Dirk Wilden committed
418
 */
Dirk Wilden's avatar
Dirk Wilden committed
419
void DataControlPlugin::slotMoveBaseObject(int _id, int _newParentId){
Dirk Wilden's avatar
Dirk Wilden committed
420

Dirk Wilden's avatar
Dirk Wilden committed
421
  BaseObject* obj = 0;
Dirk Wilden's avatar
Dirk Wilden committed
422

Dirk Wilden's avatar
Dirk Wilden committed
423 424
  if ( !PluginFunctions::getObject(_id, obj) )
    return;
Jan Möbius's avatar
 
Jan Möbius committed
425

Dirk Wilden's avatar
Dirk Wilden committed
426
  BaseObject* parent = 0;
Dirk Wilden's avatar
Dirk Wilden committed
427

Dirk Wilden's avatar
Dirk Wilden committed
428 429
  if ( !PluginFunctions::getObject(_newParentId, parent) )
    return;
Dirk Wilden's avatar
Dirk Wilden committed
430

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

Dirk Wilden's avatar
Dirk Wilden committed
433 434
  //set new parent
  obj->setParent( parent );
Dirk Wilden's avatar
Dirk Wilden committed
435

Dirk Wilden's avatar
Dirk Wilden committed
436 437 438
  //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
439 440 441 442 443 444
}


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

/** \brief Load Groups from ini file
445
 *
Dirk Wilden's avatar
Dirk Wilden committed
446 447
 * @param _ini an ini file
 */
Jan Möbius's avatar
 
Jan Möbius committed
448
void DataControlPlugin::loadIniFileOptionsLast( INIFile& _ini ) {
449 450 451 452 453 454 455 456 457 458 459 460

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

461
  if ( !_ini.section_exists( "Groups" ) )
Jan Möbius's avatar
 
Jan Möbius committed
462
    return;
463

Jan Möbius's avatar
 
Jan Möbius committed
464 465
  // Names of all groups
  QStringList groupNames;
466

Jan Möbius's avatar
 
Jan Möbius committed
467 468
  // names of the primary groups
  QStringList rootGroup;
469

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

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

Dirk Wilden's avatar
Dirk Wilden committed
476 477 478
  //list of groups
  QVector< BaseObject* > groups;

Jan Möbius's avatar
 
Jan Möbius committed
479 480 481 482
  // Go over one level of the groups
  while ( rootGroup.size() > 0 ) {
    QString current = rootGroup[0];
    rootGroup.removeFirst();
483

Jan Möbius's avatar
 
Jan Möbius committed
484 485
    QStringList groupChildren;
    QStringList elementChildren;
486

Jan Möbius's avatar
 
Jan Möbius committed
487 488
    _ini.get_entry(elementChildren ,current,"children");
    _ini.get_entry(groupChildren ,current,"subgroups");
489

Jan Möbius's avatar
 
Jan Möbius committed
490 491 492 493 494 495
    // 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 )
496 497 498 499 500 501
        parentItem = PluginFunctions::objectRoot();
    } else
      parentItem = PluginFunctions::objectRoot();

    rootGroup << groupChildren;

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

Jan Möbius's avatar
 
Jan Möbius committed
505 506
    // group does not exist
    if ( !group ) {
507

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

Dirk Wilden's avatar
Dirk Wilden committed
510 511 512 513 514 515 516 517 518
      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
519
    }
520

Jan Möbius's avatar
 
Jan Möbius committed
521 522 523 524 525 526 527 528 529 530
    // process children
    for ( int i = 0 ; i < elementChildren.size() ; ++i ) {
      BaseObject* childItem =  PluginFunctions::objectRoot()->childExists( elementChildren[i] );
      if ( childItem ) {
        childItem->setParent(group);
      }
    }
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
531 532 533 534

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

/** \brief Save groups to ini file
535
 *
Dirk Wilden's avatar
Dirk Wilden committed
536 537
 * @param _ini an ini file
 */
Jan Möbius's avatar
 
Jan Möbius committed
538
void DataControlPlugin::saveIniFileOptions( INIFile& _ini ) {
539

540 541 542
  if ( !_ini.section_exists( "Groups" ) )
    _ini.add_section("Groups");

Jan Möbius's avatar
 
Jan Möbius committed
543 544
  std::queue< BaseObject* > children;
  children.push( PluginFunctions::objectRoot() );
545

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

Jan Möbius's avatar
 
Jan Möbius committed
548 549 550 551
  // Get all groups from the tree
  while ( children.size() > 0 ) {
    BaseObject* item = children.front();
    children.pop();
552 553 554 555 556

    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
557 558 559
    if ( item->dataType(DATA_GROUP) && (item != PluginFunctions::objectRoot() ) )
      groups.push_back(item);
  }
560

Jan Möbius's avatar
 
Jan Möbius committed
561 562
  // Names of all groups
  QStringList groupNames;
563

Jan Möbius's avatar
 
Jan Möbius committed
564 565
  // names of the primary groups
  QStringList rootGroup;
566

Jan Möbius's avatar
 
Jan Möbius committed
567
  for ( uint i = 0 ; i < groups.size() ; ++i ) {
568 569 570 571 572
    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
573
    _ini.add_entry(groups[i]->name(),"groupname",groups[i]->name());
574 575

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

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

Jan Möbius's avatar
 
Jan Möbius committed
582 583 584 585 586 587 588 589 590
    // 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() );
    }
591

Jan Möbius's avatar
 
Jan Möbius committed
592 593 594
    _ini.add_entry(groups[i]->name(),"subgroups",groupchildren);
    _ini.add_entry(groups[i]->name(),"children",elementchildren);
  }
595

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

Jan Möbius's avatar
 
Jan Möbius committed
599 600
  // Write the primary group names to the file
  _ini.add_entry("Groups","rootGroup",rootGroup);
601 602 603 604 605 606 607

  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
608 609 610
}


Dirk Wilden's avatar
Dirk Wilden committed
611 612 613
//******************************************************************************

/** \brief Recursively update a column up to the root of the tree
614
 *
Dirk Wilden's avatar
Dirk Wilden committed
615 616 617 618
 * @param _obj object to start with
 */
void DataControlPlugin::propagateUpwards(BaseObject* _obj, int _column ){

619
  
Dirk Wilden's avatar
Dirk Wilden committed
620 621 622 623 624 625 626 627 628 629 630 631 632 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
  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
672
 *
Dirk Wilden's avatar
Dirk Wilden committed
673 674 675 676 677 678 679 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
 * @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);

    }
  }
}

720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
//******************************************************************************

/** \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){
768 769 770 771 772
  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 ());
773 774
}

Dirk Wilden's avatar
Dirk Wilden committed
775

Jan Möbius's avatar
 
Jan Möbius committed
776 777
Q_EXPORT_PLUGIN2( datacontrolplugin , DataControlPlugin );