DataControlPluginScripting.cc 22.9 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
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 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
42

43 44 45 46 47 48 49




#include "DataControlPlugin.hh"


50 51
//******************************************************************************

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

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

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

60 61
  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
62

63 64
  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
65

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

69 70
  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
71

72 73
  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
74

75 76 77
  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
78

79 80 81
  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
82

83 84 85
  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
86

87 88 89 90 91 92 93 94
  emit setSlotDescription("addEmptyGroup(QString)", tr("Create new empty group."),
                          QStringList(tr("GroupName")),
                          QStringList(tr("Name of the new group.")));

  emit setSlotDescription("addEmptyGroup(QString,int)", tr("Create new empty group."),
                          QString(tr("GroupName,Parent")).split(","),
                          QString(tr("Name of the new group., Parent of the new group, or -1, if there is no parent.")).split(","));

95
  emit setSlotDescription("groupObjects(IdList,QString)",tr("Group given Objects together."),
96 97
                          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
98

99
  emit setSlotDescription("groupObjects(IdList)",tr("Group given Objects together."),
100
                          QStringList(tr("objectIds")), QStringList(tr("List of objects that should be grouped.")));
101 102 103

  emit setSlotDescription("groupCount()",tr("Returns the number of group objects."),
                          QStringList(tr("")), QStringList(tr("")));
104 105 106
                          
  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
107

108 109
  emit setSlotDescription("objectDelete(int)",tr("Delete an object"),
                          QStringList(tr("objectId")), QStringList(tr("Delete the given object.")));
110

111
  emit setSlotDescription("getGroupElements(int)",tr("Get elements of a group"),
112
                          QStringList(tr("groupId")), QStringList(tr("Id of the group.")));
113

114 115
  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
116

117
  emit setSlotDescription("setAllTarget()",tr("Set All objects as targets"),
Dirk Wilden's avatar
Dirk Wilden committed
118 119
                          QStringList(), QStringList());

120
  emit setSlotDescription("setAllSource()",tr("Set All objects as source"),
Dirk Wilden's avatar
Dirk Wilden committed
121 122
                          QStringList(), QStringList());

123
  emit setSlotDescription("clearAllTarget()",tr("Clear targets"),
Dirk Wilden's avatar
Dirk Wilden committed
124 125
                          QStringList(), QStringList());

126
  emit setSlotDescription("clearAllSource()",tr("Clear sources"),
Dirk Wilden's avatar
Dirk Wilden committed
127 128
                          QStringList(), QStringList());

129
  emit setSlotDescription("showAll()",tr("Show all objects"),
Dirk Wilden's avatar
Dirk Wilden committed
130 131
                          QStringList(), QStringList());

132
  emit setSlotDescription("hideAll()",tr("Hide all objects"),
Dirk Wilden's avatar
Dirk Wilden committed
133
                          QStringList(), QStringList());
134

135
  emit setSlotDescription("availableDataTypeNames()",tr("Returns a QStringList of all available DataType names."),
136
                          QStringList(tr("")), QStringList(tr("")));
137

138
  emit setSlotDescription("printObjectInfoToLog()",tr("Print info about all objects to log"),
139
                          QStringList(), QStringList());
140

141
  emit setSlotDescription("addObjectToGroup(int,int)",tr("Add an Object to an existing group"),
142 143
                          QStringList(tr("objectId,groupId").split(",")),
                          QStringList(tr("ID of an object.,ID of an group where the object has to be added.").split(",")));
144

Dirk Wilden's avatar
Dirk Wilden committed
145 146 147
}


148 149 150
//******************************************************************************

/** \brief Returns the id of an object with given name
Jan Möbius's avatar
Jan Möbius committed
151
 *
152 153 154
 * @param _name name of an object
 * @return the id
 */
155
int DataControlPlugin::getObject( QString _name ) {
156 157 158

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

159 160
  if ( object == 0)
    return -1;
161

162 163 164
  return object->id();
}

165 166 167 168

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

/** \brief Generate a copy of an object
Jan Möbius's avatar
Jan Möbius committed
169
 *
170 171 172
 * @param objectId id of an object
 * @return id of the generated object
 */
Jan Möbius's avatar
Jan Möbius committed
173 174
int DataControlPlugin::copyObject( int objectId ) {

175 176 177
  int newObject;

  emit copyObject( objectId, newObject );
Jan Möbius's avatar
Jan Möbius committed
178 179 180 181 182

  return newObject;
}


183 184 185
//******************************************************************************

/** \brief Returns the name of an object with given id
Jan Möbius's avatar
Jan Möbius committed
186
 *
187 188 189
 * @param objectId id of an object
 * @return name of the given object
 */
190
QString DataControlPlugin::getObjectName( int objectId ) {
191

192
  BaseObjectData* object;
193
  if ( ! PluginFunctions::getObject(objectId,object) ) {
194 195
    emit log(LOGERR,tr("getObjectName : unable to get object") );
    return QString(tr("Unknown Object"));
196
  } else
197
    return  object->name() ;
198

199 200
}

201 202 203 204 205 206 207 208 209 210 211 212 213
//******************************************************************************

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

214 215 216 217

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

/** \brief Hide object with the given id
Jan Möbius's avatar
Jan Möbius committed
218
 *
219 220
 * @param objectId id of an object
 */
221
void DataControlPlugin::hideObject( int objectId ) {
222

223 224 225
  if ( ! OpenFlipper::Options::gui())
    return;

226
  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
227 228 229
  if ( PluginFunctions::getObject(objectId,object) ){
    object->hide();
  }
Dirk Wilden's avatar
Dirk Wilden committed
230

231 232
}

233 234 235 236

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

/** \brief set the given Object as target
Jan Möbius's avatar
Jan Möbius committed
237
 *
238 239 240
 * @param objectId id of an object
 * @param _target set object as target?
 */
Dirk Wilden's avatar
Dirk Wilden committed
241 242 243
void DataControlPlugin::setTarget( int objectId, bool _target ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
244 245 246
  if ( PluginFunctions::getObject(objectId,object) ){
    object->target( _target );
  }
Dirk Wilden's avatar
Dirk Wilden committed
247 248
}

249 250 251 252

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

/** \brief set the given Object as source
Jan Möbius's avatar
Jan Möbius committed
253
 *
254 255 256
 * @param objectId id of an object
 * @param _source set object as source?
 */
Dirk Wilden's avatar
Dirk Wilden committed
257 258 259
void DataControlPlugin::setSource( int objectId, bool _source ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
260 261 262
  if ( PluginFunctions::getObject(objectId,object) ){
    object->source( _source );
  }
263

Dirk Wilden's avatar
Dirk Wilden committed
264 265
}

266 267 268 269

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

/** \brief set the name of the given Object
Jan Möbius's avatar
Jan Möbius committed
270
 *
271 272 273
 * @param objectId id of an object
 * @param _name new name
 */
Dirk Wilden's avatar
Dirk Wilden committed
274 275 276
void DataControlPlugin::setObjectName( int objectId, QString _name ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
277 278 279
  if ( PluginFunctions::getObject(objectId,object) ){
    object->setName( _name );
  }
Dirk Wilden's avatar
Dirk Wilden committed
280 281
}

282 283 284 285

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

/** \brief Delete an object
Jan Möbius's avatar
Jan Möbius committed
286
 *
287 288
 * @param objectId id of the object that should be deleted
 */
289
void DataControlPlugin::objectDelete( int objectId ) {
290 291 292 293 294 295 296 297

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

  if ( object == 0)
    return;

298
  emit deleteObject(objectId);
299 300
}

301 302 303 304

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

/** \brief Show object with the given id
Jan Möbius's avatar
Jan Möbius committed
305
 *
306 307
 * @param objectId id of an object
 */
308
void DataControlPlugin::showObject( int objectId ) {
309

310 311 312
  if ( ! OpenFlipper::Options::gui())
      return;

313
  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
314 315 316
  if ( PluginFunctions::getObject(objectId,object) ){
    object->show();
  }
Dirk Wilden's avatar
Dirk Wilden committed
317

318 319
}

320

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
//******************************************************************************

/** \brief Create new empty group
*
* @param _groupName name of the new group
* @param _parentGroupId id of the parent. -1, if the new group will have no parent
*/
int DataControlPlugin::addEmptyGroup(QString _groupName, int _parentGroupId) {
	GroupObject* parentGroupObject = dynamic_cast<GroupObject*>(PluginFunctions::objectRoot());
	BaseObject* parentObject = 0;
	if (PluginFunctions::getObject(_parentGroupId, parentObject)) {
		GroupObject* parent = dynamic_cast<GroupObject*>(parentObject);
		if (parent) {
			parentGroupObject = parent;
		} else {
			emit log(LOGWARN, tr("Parent object %1 is not a group, creating a new toplevel group").arg(_parentGroupId));
		}
	} else if (_parentGroupId != 0 ) {
		emit log(LOGWARN, tr("Cannot get parent object %1, creating a new toplevel group").arg(_parentGroupId));
	}

	GroupObject* groupObject = new GroupObject("newGroup", parentGroupObject);

	if (_groupName == "") {
		groupObject->setName(tr("New group ") + QString::number(groupObject->id()));
	} else {
		groupObject->setName(_groupName);
	}

	emit emptyObjectAdded(groupObject->id());

	return groupObject->id();
}

355 356 357
//******************************************************************************

/** \brief Group given Objects together
Jan Möbius's avatar
Jan Möbius committed
358
 *
359 360 361
 * @param _objectIDs list of object ids
 * @param _groupName the name of the new group
 */
Jan Möbius's avatar
Jan Möbius committed
362
int DataControlPlugin::groupObjects(IdList _objectIDs, QString _groupName) {
Dirk Wilden's avatar
Dirk Wilden committed
363 364
  QVector< BaseObject* > objs;

365
  // Try to get all objects given in list
Dirk Wilden's avatar
Dirk Wilden committed
366 367
  for (uint i=0; i < _objectIDs.size(); i++){
    BaseObject* obj;
368
    if ( PluginFunctions::getObject(_objectIDs[i],obj) )
Dirk Wilden's avatar
Dirk Wilden committed
369 370 371
      objs.push_back(obj);
  }

372
  // If all of them fail, stop here.
Dirk Wilden's avatar
Dirk Wilden committed
373
  if (objs.size() == 0){
374
    emit log(tr("No objects to group."));
375
    return -1;
Dirk Wilden's avatar
Dirk Wilden committed
376
  }
377

378
  // Check if all objects have the same parent
379
  // Abort if the parents differ
Dirk Wilden's avatar
Dirk Wilden committed
380
  BaseObject* parent = (objs[0])->parent();
381
  for ( int i = 1 ; i < objs.size() ; ++i){
Dirk Wilden's avatar
Dirk Wilden committed
382
    if ( parent != (objs[i])->parent() ){
383
      emit log(tr("Cannot group Objects with different parents"));
384
      return -1;
Dirk Wilden's avatar
Dirk Wilden committed
385 386
    }

387 388
  }

Dirk Wilden's avatar
Dirk Wilden committed
389
  //create new group
390 391 392
  int groupId = addEmptyGroup(_groupName);
  BaseObject *groupItem = 0;
  PluginFunctions::getObject(groupId, groupItem);
Dirk Wilden's avatar
Dirk Wilden committed
393

394 395 396
  if (parent) {
    groupItem->setParent(parent);
  }
Dirk Wilden's avatar
Dirk Wilden committed
397

398
  IdList ids;
Dirk Wilden's avatar
Dirk Wilden committed
399
  //append new children to group
400 401
  for ( int i = 0 ; i < objs.size() ; ++i)
  {
402
    (objs[i])->setParent(groupItem);
403
    ids.push_back((objs[i])->id());
Dirk Wilden's avatar
Dirk Wilden committed
404
  }
405 406 407

  emit objectsGrouped(ids);
  emit updatedObject(groupId,UPDATE_ALL);
408
  
409
  return groupId;
Dirk Wilden's avatar
Dirk Wilden committed
410
}
411

412 413
//******************************************************************************

414
bool DataControlPlugin::unGroupObject(int _id) {
415
  BaseObject* group = 0;
416
  
417
  PluginFunctions::getObject(_id,group);
418
 
419 420 421 422 423 424 425 426 427 428 429 430
  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() );

431 432
    return true;
  } else {
433 434 435 436
    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) );
437 438 439 440
    return false;
  }
}

441 442 443

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

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

  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) ;
458 459 460
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->target(true);
  }
Dirk Wilden's avatar
Dirk Wilden committed
461 462
}

463 464 465 466

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

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

  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) ;
480 481 482
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->source(true);
  }
Dirk Wilden's avatar
Dirk Wilden committed
483 484
}

485 486 487

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

Jan Möbius's avatar
Jan Möbius committed
488 489
/** \brief Clear Target Selection for all objects
 *
490
 */
Dirk Wilden's avatar
Dirk Wilden committed
491
void DataControlPlugin::clearAllTarget() {
492 493 494 495 496 497 498 499 500 501

  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) ;
502 503 504
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->target(false);
  }
Dirk Wilden's avatar
Dirk Wilden committed
505 506
}

507 508 509 510

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

/** \brief Clear Source Selection for all objects
Jan Möbius's avatar
Jan Möbius committed
511
 *
512
 */
Dirk Wilden's avatar
Dirk Wilden committed
513
void DataControlPlugin::clearAllSource() {
514 515 516 517 518 519 520 521 522 523

  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) ;
524 525 526
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->source(false);
  }
Dirk Wilden's avatar
Dirk Wilden committed
527 528
}

529 530 531 532

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

/** \brief Hide all objects
Jan Möbius's avatar
Jan Möbius committed
533
 *
534
 */
Dirk Wilden's avatar
Dirk Wilden committed
535
void DataControlPlugin::hideAll() {
536

537 538 539
  if ( ! OpenFlipper::Options::gui())
      return;

540 541 542 543 544 545 546 547 548
  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) ;
549
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
Dirk Wilden's avatar
Dirk Wilden committed
550
    o_it->hide();
551 552
  }

Dirk Wilden's avatar
Dirk Wilden committed
553 554
}

555 556 557 558

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

/** \brief Show all objects
Jan Möbius's avatar
Jan Möbius committed
559
 *
560
 */
Dirk Wilden's avatar
Dirk Wilden committed
561
void DataControlPlugin::showAll() {
562

563 564 565
  if ( ! OpenFlipper::Options::gui())
      return;

566 567 568 569 570 571 572 573 574
  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
575
    o_it->show();
576 577
  }

Dirk Wilden's avatar
Dirk Wilden committed
578
}
579 580 581 582 583 584 585 586 587 588 589 590

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

/** \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() );
591

592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
  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;  
}

610 611 612 613 614 615
//******************************************************************************

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

617 618 619
  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()));
}
620

621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
//******************************************************************************

/** \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;
}

//******************************************************************************
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655

/** \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;
}

//******************************************************************************
656 657 658 659 660 661
/** \brief add an object to an existing group
 *
 * add the object with _objectId to the group with _groupId
 *
 * @return success
*/
662
bool DataControlPlugin::addObjectToGroup(int _objectId, int _groupId)
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
{
  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;
}
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706

//******************************************************************************
/** \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;
}