DataControlPluginScripting.cc 21.3 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
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
*                           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/>.                                       *
*                                                                            *
33 34 35
\*===========================================================================*/

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




#include "DataControlPlugin.hh"

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>


51 52
//******************************************************************************

Dirk Wilden's avatar
Dirk Wilden committed
53 54
void DataControlPlugin::setDescriptions(){

55 56 57 58 59 60
  emit setSlotDescription("getSourceObjects(DataType)",tr("Returns the IdList of all source objects with given DataType."),
                            QStringList(tr("Datatype")), QStringList(tr("Datatype of the objects")));

  emit setSlotDescription("getTargetObjects(DataType)",tr("Returns the IdList of all target objects with given DataType."),
                              QStringList(tr("Datatype")), QStringList(tr("Datatype of the objects")));

Jan Möbius's avatar
Jan Möbius committed
61 62
  emit setSlotDescription("getObject(QString)",tr("Returns the id of an object with given name."),
                          QStringList(tr("Name")), QStringList(tr("Name of an object")));
Dirk Wilden's avatar
Dirk Wilden committed
63

Jan Möbius's avatar
Jan Möbius committed
64 65
  emit setSlotDescription("getObjectName(int)",tr("Returns the name of an object with given id."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
Dirk Wilden's avatar
Dirk Wilden committed
66

67 68 69
  emit setSlotDescription("dataType(int)",tr("Returns the DataType of the object with the given id."),
                            QStringList(tr("objectId")), QStringList(tr("ID of an object")));

Jan Möbius's avatar
Jan Möbius committed
70 71
  emit setSlotDescription("hideObject(int)",tr("Hide object with the given id."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
Dirk Wilden's avatar
Dirk Wilden committed
72

Jan Möbius's avatar
Jan Möbius committed
73 74
  emit setSlotDescription("showObject(int)",tr("Show object with the given id."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
Dirk Wilden's avatar
Dirk Wilden committed
75

Jan Möbius's avatar
Jan Möbius committed
76 77 78
  emit setSlotDescription("setTarget(int,bool)",tr("Set given object as target."),
                          QString(tr("ObjectId,Target")).split(","),
                          QString(tr("id of the object, set object as target?")).split(","));
Dirk Wilden's avatar
Dirk Wilden committed
79

Jan Möbius's avatar
Jan Möbius committed
80 81 82
  emit setSlotDescription("setSource(int,bool)",tr("Set given object as source."),
                          QString(tr("ObjectId,Source")).split(","),
                          QString(tr("id of the object, set object as source?")).split(","));
Dirk Wilden's avatar
Dirk Wilden committed
83

Jan Möbius's avatar
Jan Möbius committed
84 85 86
  emit setSlotDescription("setObjectName(int,QString)",tr("Set name of given object."),
                          QString(tr("ObjectId,name")).split(","),
                          QString(tr("id of the object, the new name")).split(","));
Dirk Wilden's avatar
Dirk Wilden committed
87

88
  emit setSlotDescription("groupObjects(IdList,QString)",tr("Group given Objects together."),
Jan Möbius's avatar
Jan Möbius committed
89 90
                          QString(tr("objectIds,groupName")).split(","),
                          QString(tr("List of objects that should be grouped., Name of the group.")).split(","));
Dirk Wilden's avatar
Dirk Wilden committed
91

92
  emit setSlotDescription("groupObjects(IdList)",tr("Group given Objects together."),
Jan Möbius's avatar
Jan Möbius committed
93
                          QStringList(tr("objectIds")), QStringList(tr("List of objects that should be grouped.")));
94 95 96

  emit setSlotDescription("groupCount()",tr("Returns the number of group objects."),
                          QStringList(tr("")), QStringList(tr("")));
97 98 99
                          
  emit setSlotDescription("unGroupObject(int)",tr("Remove the given object from its group and append to root node."),
                          QStringList(tr("ObjectId")), QStringList(tr("Object to be removed from group.")));                          
Dirk Wilden's avatar
Dirk Wilden committed
100

Jan Möbius's avatar
Jan Möbius committed
101 102
  emit setSlotDescription("objectDelete(int)",tr("Delete an object"),
                          QStringList(tr("objectId")), QStringList(tr("Delete the given object.")));
103

104 105 106
  emit setSlotDescription("getGroupElements(int)",tr("Get elements of a group"),
                           QStringList(tr("groupId")), QStringList(tr("Id of the group.")));

Jan Möbius's avatar
Jan Möbius committed
107 108
  emit setSlotDescription("copyObject(int)",tr("Create a copy of an object"),
                          QStringList(tr("objectId")), QStringList(tr("Object to copy.")));
Jan Möbius's avatar
Jan Möbius committed
109

Jan Möbius's avatar
Jan Möbius committed
110
  emit setSlotDescription("setAllTarget()",tr("Set All objects as targets"),
Dirk Wilden's avatar
Dirk Wilden committed
111 112
                          QStringList(), QStringList());

Jan Möbius's avatar
Jan Möbius committed
113
  emit setSlotDescription("setAllSource()",tr("Set All objects as source"),
Dirk Wilden's avatar
Dirk Wilden committed
114 115
                          QStringList(), QStringList());

Jan Möbius's avatar
Jan Möbius committed
116
  emit setSlotDescription("clearAllTarget()",tr("Clear targets"),
Dirk Wilden's avatar
Dirk Wilden committed
117 118
                          QStringList(), QStringList());

Jan Möbius's avatar
Jan Möbius committed
119
  emit setSlotDescription("clearAllSource()",tr("Clear sources"),
Dirk Wilden's avatar
Dirk Wilden committed
120 121
                          QStringList(), QStringList());

Jan Möbius's avatar
Jan Möbius committed
122
  emit setSlotDescription("showAll()",tr("Show all objects"),
Dirk Wilden's avatar
Dirk Wilden committed
123 124
                          QStringList(), QStringList());

Jan Möbius's avatar
Jan Möbius committed
125
  emit setSlotDescription("hideAll()",tr("Hide all objects"),
Dirk Wilden's avatar
Dirk Wilden committed
126
                          QStringList(), QStringList());
127

128 129 130
  emit setSlotDescription("availableDataTypeNames()",tr("Returns a QStringList of all available DataType names."),
                              QStringList(tr("")), QStringList(tr("")));

131 132 133
  emit setSlotDescription("printObjectInfoToLog()",tr("Print info about all objects to log"),
                            QStringList(), QStringList());

Matthias Möller's avatar
Matthias Möller committed
134
  emit setSlotDescription("addObjectToGroup(int,int)",tr("Add an Object to an existing group"),
135 136 137
                            QStringList(tr("objectId,groupId").split(",")),
                            QStringList(tr("ID of an object.,ID of an group where the object has to be added.").split(",")));

Dirk Wilden's avatar
Dirk Wilden committed
138 139 140
}


141 142 143
//******************************************************************************

/** \brief Returns the id of an object with given name
Jan Möbius's avatar
Jan Möbius committed
144
 *
145 146 147
 * @param _name name of an object
 * @return the id
 */
Jan Möbius's avatar
 
Jan Möbius committed
148
int DataControlPlugin::getObject( QString _name ) {
149 150 151

  BaseObject* object = PluginFunctions::objectRoot()->childExists(_name);

Jan Möbius's avatar
 
Jan Möbius committed
152 153
  if ( object == 0)
    return -1;
154

Jan Möbius's avatar
 
Jan Möbius committed
155 156 157
  return object->id();
}

158 159 160 161

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

/** \brief Generate a copy of an object
Jan Möbius's avatar
Jan Möbius committed
162
 *
163 164 165
 * @param objectId id of an object
 * @return id of the generated object
 */
Jan Möbius's avatar
Jan Möbius committed
166 167
int DataControlPlugin::copyObject( int objectId ) {

168 169 170
  int newObject;

  emit copyObject( objectId, newObject );
Jan Möbius's avatar
Jan Möbius committed
171 172 173 174 175

  return newObject;
}


176 177 178
//******************************************************************************

/** \brief Returns the name of an object with given id
Jan Möbius's avatar
Jan Möbius committed
179
 *
180 181 182
 * @param objectId id of an object
 * @return name of the given object
 */
Jan Möbius's avatar
 
Jan Möbius committed
183
QString DataControlPlugin::getObjectName( int objectId ) {
184

Jan Möbius's avatar
 
Jan Möbius committed
185
  BaseObjectData* object;
Jan Möbius's avatar
 
Jan Möbius committed
186
  if ( ! PluginFunctions::getObject(objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
187 188
    emit log(LOGERR,tr("getObjectName : unable to get object") );
    return QString(tr("Unknown Object"));
189
  } else
Jan Möbius's avatar
 
Jan Möbius committed
190
    return  object->name() ;
191

Jan Möbius's avatar
 
Jan Möbius committed
192 193
}

194 195 196 197 198 199 200 201 202 203 204 205 206
//******************************************************************************

/// Get the DataType of a given object
DataType DataControlPlugin::dataType( int _objectId ) {
  BaseObject* object = 0;
  PluginFunctions::getObject(_objectId,object);

  if ( object )
    return object->dataType();
  else
    return DATA_UNKNOWN;
}

207 208 209 210

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

/** \brief Hide object with the given id
Jan Möbius's avatar
Jan Möbius committed
211
 *
212 213
 * @param objectId id of an object
 */
Jan Möbius's avatar
 
Jan Möbius committed
214
void DataControlPlugin::hideObject( int objectId ) {
215

216 217 218
  if ( ! OpenFlipper::Options::gui())
    return;

Jan Möbius's avatar
 
Jan Möbius committed
219
  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
220 221 222
  if ( PluginFunctions::getObject(objectId,object) ){
    object->hide();
  }
Dirk Wilden's avatar
Dirk Wilden committed
223

Jan Möbius's avatar
 
Jan Möbius committed
224 225
}

226 227 228 229

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

/** \brief set the given Object as target
Jan Möbius's avatar
Jan Möbius committed
230
 *
231 232 233
 * @param objectId id of an object
 * @param _target set object as target?
 */
Dirk Wilden's avatar
Dirk Wilden committed
234 235 236
void DataControlPlugin::setTarget( int objectId, bool _target ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
237 238 239
  if ( PluginFunctions::getObject(objectId,object) ){
    object->target( _target );
  }
Dirk Wilden's avatar
Dirk Wilden committed
240 241
}

242 243 244 245

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

/** \brief set the given Object as source
Jan Möbius's avatar
Jan Möbius committed
246
 *
247 248 249
 * @param objectId id of an object
 * @param _source set object as source?
 */
Dirk Wilden's avatar
Dirk Wilden committed
250 251 252
void DataControlPlugin::setSource( int objectId, bool _source ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
253 254 255
  if ( PluginFunctions::getObject(objectId,object) ){
    object->source( _source );
  }
256

Dirk Wilden's avatar
Dirk Wilden committed
257 258
}

259 260 261 262

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

/** \brief set the name of the given Object
Jan Möbius's avatar
Jan Möbius committed
263
 *
264 265 266
 * @param objectId id of an object
 * @param _name new name
 */
Dirk Wilden's avatar
Dirk Wilden committed
267 268 269
void DataControlPlugin::setObjectName( int objectId, QString _name ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
270 271 272
  if ( PluginFunctions::getObject(objectId,object) ){
    object->setName( _name );
  }
Dirk Wilden's avatar
Dirk Wilden committed
273 274
}

275 276 277 278

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

/** \brief Delete an object
Jan Möbius's avatar
Jan Möbius committed
279
 *
280 281
 * @param objectId id of the object that should be deleted
 */
282
void DataControlPlugin::objectDelete( int objectId ) {
283 284 285 286 287 288 289 290

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(objectId,object) )
    return;

  if ( object == 0)
    return;

291
  emit deleteObject(objectId);
292 293
}

294 295 296 297

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

/** \brief Show object with the given id
Jan Möbius's avatar
Jan Möbius committed
298
 *
299 300
 * @param objectId id of an object
 */
Jan Möbius's avatar
 
Jan Möbius committed
301
void DataControlPlugin::showObject( int objectId ) {
302

303 304 305
  if ( ! OpenFlipper::Options::gui())
      return;

Jan Möbius's avatar
 
Jan Möbius committed
306
  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
307 308 309
  if ( PluginFunctions::getObject(objectId,object) ){
    object->show();
  }
Dirk Wilden's avatar
Dirk Wilden committed
310

Jan Möbius's avatar
 
Jan Möbius committed
311 312
}

313 314 315 316

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

/** \brief Group given Objects together
Jan Möbius's avatar
Jan Möbius committed
317
 *
318 319 320
 * @param _objectIDs list of object ids
 * @param _groupName the name of the new group
 */
Jan Möbius's avatar
Jan Möbius committed
321
int DataControlPlugin::groupObjects(IdList _objectIDs, QString _groupName) {
Dirk Wilden's avatar
Dirk Wilden committed
322 323
  QVector< BaseObject* > objs;

324
  // Try to get all objects given in list
Dirk Wilden's avatar
Dirk Wilden committed
325 326
  for (uint i=0; i < _objectIDs.size(); i++){
    BaseObject* obj;
Jan Möbius's avatar
 
Jan Möbius committed
327
    if ( PluginFunctions::getObject(_objectIDs[i],obj) )
Dirk Wilden's avatar
Dirk Wilden committed
328 329 330
      objs.push_back(obj);
  }

331
  // If all of them fail, stop here.
Dirk Wilden's avatar
Dirk Wilden committed
332
  if (objs.size() == 0){
Jan Möbius's avatar
Jan Möbius committed
333
    emit log(tr("No objects to group."));
334
    return -1;
Dirk Wilden's avatar
Dirk Wilden committed
335
  }
336

337
  // Check if all objects have the same parent
338
  // Abort if the parents differ
Dirk Wilden's avatar
Dirk Wilden committed
339
  BaseObject* parent = (objs[0])->parent();
340
  for ( int i = 1 ; i < objs.size() ; ++i){
Dirk Wilden's avatar
Dirk Wilden committed
341
    if ( parent != (objs[i])->parent() ){
Jan Möbius's avatar
Jan Möbius committed
342
      emit log(tr("Cannot group Objects with different parents"));
343
      return -1;
Dirk Wilden's avatar
Dirk Wilden committed
344 345
    }

346 347
  }

Dirk Wilden's avatar
Dirk Wilden committed
348 349 350
  //create new group
  if (parent == 0)
    parent = PluginFunctions::objectRoot();
Dirk Wilden's avatar
Dirk Wilden committed
351

Dirk Wilden's avatar
Dirk Wilden committed
352
  GroupObject* groupItem = new GroupObject( "newGroup", dynamic_cast< GroupObject* >(parent));
Dirk Wilden's avatar
Dirk Wilden committed
353

Dirk Wilden's avatar
Dirk Wilden committed
354 355
  //set groupName
  if (_groupName == "")
Jan Möbius's avatar
Jan Möbius committed
356
    groupItem->setName(tr("newGroup ") + QString::number(groupItem->id()));
Dirk Wilden's avatar
Dirk Wilden committed
357 358 359
  else
    groupItem->setName( _groupName );

360
  // Tell core that a new group has been added
Dirk Wilden's avatar
Dirk Wilden committed
361 362
  emit emptyObjectAdded( groupItem->id() );

Dirk Wilden's avatar
Dirk Wilden committed
363 364 365 366
  //append new children to group
  for ( int i = 0 ; i < objs.size() ; ++i) {
    (objs[i])->setParent( dynamic_cast< BaseObject* >( groupItem )  );
  }
367 368
  
  return groupItem->id();
Dirk Wilden's avatar
Dirk Wilden committed
369
}
Jan Möbius's avatar
 
Jan Möbius committed
370

371
bool DataControlPlugin::unGroupObject(int _id) {
372
  BaseObject* group = 0;
373
  
374
  PluginFunctions::getObject(_id,group);
375
 
376 377 378 379 380 381 382 383 384 385 386 387
  if ( group && group->isGroup())
  {
    //iterate over children
    for (int i=group->childCount()-1; i >= 0; --i){
      BaseObject* child = group->child(i);

      // then change the parent
      child->setParent(group->parent());
    }
    //delete the group
    emit deleteObject( group->id() );

388 389
    return true;
  } else {
390 391 392 393
    if (group)
      emit log( LOGERR, tr("Cannot Ungroup. Object with id %1 is not a group").arg(_id));
    else
      emit log( LOGERR, tr( "Unable to get Object with id %1 for ungrouping").arg(_id) );
394 395 396 397
    return false;
  }
}

398 399 400

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

Dirk Wilden's avatar
Dirk Wilden committed
401
/** \brief Set Target Selection for all objects
Jan Möbius's avatar
Jan Möbius committed
402
 *
403
 */
Dirk Wilden's avatar
Dirk Wilden committed
404
void DataControlPlugin::setAllTarget() {
405 406 407 408 409 410 411 412 413 414

  DataType type = DATA_ALL;

  //try to find dataType restriction if called by contextMenu
  QAction* action = dynamic_cast< QAction* > ( sender() );

  if ( action != 0 && action->data().isValid() )
    type = (DataType) action->data().toUInt();

  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS, type) ;
415 416 417
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->target(true);
  }
Dirk Wilden's avatar
Dirk Wilden committed
418 419
}

420 421 422 423

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

/** \brief Set Source Selection for all objects
Jan Möbius's avatar
Jan Möbius committed
424
 *
425
 */
Dirk Wilden's avatar
Dirk Wilden committed
426
void DataControlPlugin::setAllSource() {
427 428 429 430 431 432 433 434 435 436

  DataType type = DATA_ALL;

  //try to find dataType restriction if called by contextMenu
  QAction* action = dynamic_cast< QAction* > ( sender() );

  if ( action != 0 && action->data().isValid() )
    type = (DataType) action->data().toUInt();

  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS, type) ;
437 438 439
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->source(true);
  }
Dirk Wilden's avatar
Dirk Wilden committed
440 441
}

442 443 444

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

Jan Möbius's avatar
Jan Möbius committed
445 446
/** \brief Clear Target Selection for all objects
 *
447
 */
Dirk Wilden's avatar
Dirk Wilden committed
448
void DataControlPlugin::clearAllTarget() {
449 450 451 452 453 454 455 456 457 458

  DataType type = DATA_ALL;

  //try to find dataType restriction if called by contextMenu
  QAction* action = dynamic_cast< QAction* > ( sender() );

  if ( action != 0 && action->data().isValid() )
    type = (DataType) action->data().toUInt();

  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS, type) ;
459 460 461
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->target(false);
  }
Dirk Wilden's avatar
Dirk Wilden committed
462 463
}

464 465 466 467

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

/** \brief Clear Source Selection for all objects
Jan Möbius's avatar
Jan Möbius committed
468
 *
469
 */
Dirk Wilden's avatar
Dirk Wilden committed
470
void DataControlPlugin::clearAllSource() {
471 472 473 474 475 476 477 478 479 480

  DataType type = DATA_ALL;

  //try to find dataType restriction if called by contextMenu
  QAction* action = dynamic_cast< QAction* > ( sender() );

  if ( action != 0 && action->data().isValid() )
    type = (DataType) action->data().toUInt();

  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS, type) ;
481 482 483
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->source(false);
  }
Dirk Wilden's avatar
Dirk Wilden committed
484 485
}

486 487 488 489

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

/** \brief Hide all objects
Jan Möbius's avatar
Jan Möbius committed
490
 *
491
 */
Dirk Wilden's avatar
Dirk Wilden committed
492
void DataControlPlugin::hideAll() {
493

494 495 496
  if ( ! OpenFlipper::Options::gui())
      return;

497 498 499 500 501 502 503 504 505
  DataType type = DATA_ALL;

  //try to find dataType restriction if called by contextMenu
  QAction* action = dynamic_cast< QAction* > ( sender() );

  if ( action != 0 && action->data().isValid() )
    type = (DataType) action->data().toUInt();

  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,type) ;
506
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
Dirk Wilden's avatar
Dirk Wilden committed
507
    o_it->hide();
508 509
  }

Dirk Wilden's avatar
Dirk Wilden committed
510 511
}

512 513 514 515

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

/** \brief Show all objects
Jan Möbius's avatar
Jan Möbius committed
516
 *
517
 */
Dirk Wilden's avatar
Dirk Wilden committed
518
void DataControlPlugin::showAll() {
519

520 521 522
  if ( ! OpenFlipper::Options::gui())
      return;

523 524 525 526 527 528 529 530 531
  DataType type = DATA_ALL;

  //try to find dataType restriction if called by contextMenu
  QAction* action = dynamic_cast< QAction* > ( sender() );

  if ( action != 0 && action->data().isValid() )
    type = (DataType) action->data().toUInt();

  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS, type); o_it != PluginFunctions::objectsEnd(); ++o_it){
Dirk Wilden's avatar
Dirk Wilden committed
532
    o_it->show();
533 534
  }

Dirk Wilden's avatar
Dirk Wilden committed
535
}
536 537 538 539 540 541 542 543 544 545 546 547

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

/** \brief Get all target objects of given type
 *
 */
IdList DataControlPlugin::getTargetObjects(DataType _type) {

  IdList list;
  
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS, _type); o_it != PluginFunctions::objectsEnd(); ++o_it)
    list.push_back( o_it->id() );
548

549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
  return list;
}

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

/** \brief Get all source objects of given type
 *
 */
IdList DataControlPlugin::getSourceObjects(DataType _type) {
  
  IdList list;
  
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS, _type); o_it != PluginFunctions::objectsEnd(); ++o_it)
    list.push_back( o_it->id() );
    
  return list;  
}

567 568 569 570 571 572
//******************************************************************************

/** \brief Prints information about all open objects to the Log
 *
 */
void DataControlPlugin::printObjectInfoToLog() {
573

574 575 576
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS); o_it != PluginFunctions::objectsEnd(); ++o_it)
    emit log(LOGINFO, tr("Object \"%1\" with ID %2 of type %3 ").arg(o_it->name()).arg(o_it->id()).arg(o_it->dataType().name()));
}
577

578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
//******************************************************************************

/** \brief get number of groups
 *
 * Returns the number of groups that are in the scene
 *
 * @return Number of groups
 */
unsigned int DataControlPlugin::groupCount() const {
  unsigned int count = 0;
  for ( PluginFunctions::BaseObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_GROUP); o_it != PluginFunctions::objectsEnd(); ++o_it)
    ++count;

  return count;
}

//******************************************************************************
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612

/** \brief Return available dataType
 *
 * Returns a space separated list of all available DataTypes
 *
 * @return List of available data types
 */
QStringList DataControlPlugin::availableDataTypeNames() const {

  QStringList list;

  for ( std::vector< TypeInfo >::const_iterator dataType = typesBegin(); dataType != typesEnd(); ++dataType )
    list.push_back(dataType->name);

  return list;
}

//******************************************************************************
613 614 615 616 617 618
/** \brief add an object to an existing group
 *
 * add the object with _objectId to the group with _groupId
 *
 * @return success
*/
Matthias Möller's avatar
Matthias Möller committed
619
bool DataControlPlugin::addObjectToGroup(int _objectId, int _groupId)
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
{
  BaseObject* obj = 0;
  BaseObject* group = 0;

  PluginFunctions::getObject(_objectId,obj);
  PluginFunctions::getObject(_groupId,group);

   if ( obj && group)
   {
     if (group->isGroup())
     {
       obj->setParent(group);
       return true;
     }
     else
       emit log( LOGERR, tr(" Object with id %1 is not a group").arg(_groupId));
   } else {
       if (!obj)
         emit log( LOGERR, tr( "Unable to get Object with id %1").arg(_objectId) );
       if (!_groupId)
         emit log( LOGERR, tr( "Unable to get Group with id %1").arg(_groupId) );
   }
   return false;
}
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663

//******************************************************************************
/** \brief get all objects of an given group
 *
 * get all objects of an given group with id _groupId
 *
 * @return id list of group elements
*/

IdList DataControlPlugin::getGroupElements(int _groupId)
{
  BaseObject* group = 0;
  PluginFunctions::getObject(_groupId,group);
  IdList result;

  for (int i = 0; i < group->childCount(); ++i)
    result.push_back(group->child(i)->id());

  return result;
}