DataControlPluginScripting.cc 23.3 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 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
49 50 51 52 53 54 55




#include "DataControlPlugin.hh"


56 57
//******************************************************************************

Dirk Wilden's avatar
Dirk Wilden committed
58 59
void DataControlPlugin::setDescriptions(){

60
  emit setSlotDescription("getSourceObjects(DataType)",tr("Returns the IdList of all source objects with given DataType."),
61
                          QStringList(tr("Datatype")), QStringList(tr("Datatype of the objects")));
62 63

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

66 67
  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
68

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

72
  emit setSlotDescription("dataType(int)",tr("Returns the DataType of the object with the given id."),
73
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
74

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

78 79
  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
80

81 82 83
  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
84

85 86 87
  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
88

89 90 91
  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
92

93 94 95 96 97 98 99 100
  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(","));

101
  emit setSlotDescription("groupObjects(IdList,QString)",tr("Group given Objects together."),
102 103
                          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
104

105
  emit setSlotDescription("groupObjects(IdList)",tr("Group given Objects together."),
106
                          QStringList(tr("objectIds")), QStringList(tr("List of objects that should be grouped.")));
107 108 109

  emit setSlotDescription("groupCount()",tr("Returns the number of group objects."),
                          QStringList(tr("")), QStringList(tr("")));
110 111 112
                          
  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
113

114 115
  emit setSlotDescription("objectDelete(int)",tr("Delete an object"),
                          QStringList(tr("objectId")), QStringList(tr("Delete the given object.")));
116

117
  emit setSlotDescription("getGroupElements(int)",tr("Get elements of a group"),
118
                          QStringList(tr("groupId")), QStringList(tr("Id of the group.")));
119

120 121
  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
122

123
  emit setSlotDescription("setAllTarget()",tr("Set All objects as targets"),
Dirk Wilden's avatar
Dirk Wilden committed
124 125
                          QStringList(), QStringList());

126
  emit setSlotDescription("setAllSource()",tr("Set All objects as source"),
Dirk Wilden's avatar
Dirk Wilden committed
127 128
                          QStringList(), QStringList());

129
  emit setSlotDescription("clearAllTarget()",tr("Clear targets"),
Dirk Wilden's avatar
Dirk Wilden committed
130 131
                          QStringList(), QStringList());

132
  emit setSlotDescription("clearAllSource()",tr("Clear sources"),
Dirk Wilden's avatar
Dirk Wilden committed
133 134
                          QStringList(), QStringList());

135
  emit setSlotDescription("showAll()",tr("Show all objects"),
Dirk Wilden's avatar
Dirk Wilden committed
136 137
                          QStringList(), QStringList());

138
  emit setSlotDescription("hideAll()",tr("Hide all objects"),
Dirk Wilden's avatar
Dirk Wilden committed
139
                          QStringList(), QStringList());
140

141
  emit setSlotDescription("availableDataTypeNames()",tr("Returns a QStringList of all available DataType names."),
142
                          QStringList(tr("")), QStringList(tr("")));
143

144
  emit setSlotDescription("printObjectInfoToLog()",tr("Print info about all objects to log"),
145
                          QStringList(), QStringList());
146

147
  emit setSlotDescription("addObjectToGroup(int,int)",tr("Add an Object to an existing group"),
148 149
                          QStringList(tr("objectId,groupId").split(",")),
                          QStringList(tr("ID of an object.,ID of an group where the object has to be added.").split(",")));
150

Dirk Wilden's avatar
Dirk Wilden committed
151 152 153
}


154 155 156
//******************************************************************************

/** \brief Returns the id of an object with given name
Jan Möbius's avatar
Jan Möbius committed
157
 *
158 159 160
 * @param _name name of an object
 * @return the id
 */
161
int DataControlPlugin::getObject( QString _name ) {
162 163 164

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

165 166
  if ( object == 0)
    return -1;
167

168 169 170
  return object->id();
}

171 172 173 174

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

/** \brief Generate a copy of an object
Jan Möbius's avatar
Jan Möbius committed
175
 *
176 177 178
 * @param objectId id of an object
 * @return id of the generated object
 */
Jan Möbius's avatar
Jan Möbius committed
179 180
int DataControlPlugin::copyObject( int objectId ) {

181 182 183
  int newObject;

  emit copyObject( objectId, newObject );
Jan Möbius's avatar
Jan Möbius committed
184 185 186 187 188

  return newObject;
}


189 190 191
//******************************************************************************

/** \brief Returns the name of an object with given id
Jan Möbius's avatar
Jan Möbius committed
192
 *
193 194 195
 * @param objectId id of an object
 * @return name of the given object
 */
196
QString DataControlPlugin::getObjectName( int objectId ) {
197

198
  BaseObjectData* object;
199
  if ( ! PluginFunctions::getObject(objectId,object) ) {
200 201
    emit log(LOGERR,tr("getObjectName : unable to get object") );
    return QString(tr("Unknown Object"));
202
  } else
203
    return  object->name() ;
204

205 206
}

207 208 209 210 211 212 213 214 215 216 217 218 219
//******************************************************************************

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

220 221 222 223

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

/** \brief Hide object with the given id
Jan Möbius's avatar
Jan Möbius committed
224
 *
225 226
 * @param objectId id of an object
 */
227
void DataControlPlugin::hideObject( int objectId ) {
228

229 230 231
  if ( ! OpenFlipper::Options::gui())
    return;

232
  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
233 234 235
  if ( PluginFunctions::getObject(objectId,object) ){
    object->hide();
  }
Dirk Wilden's avatar
Dirk Wilden committed
236

237 238
}

239 240 241 242

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

/** \brief set the given Object as target
Jan Möbius's avatar
Jan Möbius committed
243
 *
244 245 246
 * @param objectId id of an object
 * @param _target set object as target?
 */
Dirk Wilden's avatar
Dirk Wilden committed
247 248 249
void DataControlPlugin::setTarget( int objectId, bool _target ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
250 251 252
  if ( PluginFunctions::getObject(objectId,object) ){
    object->target( _target );
  }
Dirk Wilden's avatar
Dirk Wilden committed
253 254
}

255 256 257 258

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

/** \brief set the given Object as source
Jan Möbius's avatar
Jan Möbius committed
259
 *
260 261 262
 * @param objectId id of an object
 * @param _source set object as source?
 */
Dirk Wilden's avatar
Dirk Wilden committed
263 264 265
void DataControlPlugin::setSource( int objectId, bool _source ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
266 267 268
  if ( PluginFunctions::getObject(objectId,object) ){
    object->source( _source );
  }
269

Dirk Wilden's avatar
Dirk Wilden committed
270 271
}

272 273 274 275

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

/** \brief set the name of the given Object
Jan Möbius's avatar
Jan Möbius committed
276
 *
277 278 279
 * @param objectId id of an object
 * @param _name new name
 */
Dirk Wilden's avatar
Dirk Wilden committed
280 281 282
void DataControlPlugin::setObjectName( int objectId, QString _name ) {

  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
283 284 285
  if ( PluginFunctions::getObject(objectId,object) ){
    object->setName( _name );
  }
Dirk Wilden's avatar
Dirk Wilden committed
286 287
}

288 289 290 291

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

/** \brief Delete an object
Jan Möbius's avatar
Jan Möbius committed
292
 *
293 294
 * @param objectId id of the object that should be deleted
 */
295
void DataControlPlugin::objectDelete( int objectId ) {
296 297 298 299 300 301 302 303

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

  if ( object == 0)
    return;

304
  emit deleteObject(objectId);
305 306
}

307 308 309 310

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

/** \brief Show object with the given id
Jan Möbius's avatar
Jan Möbius committed
311
 *
312 313
 * @param objectId id of an object
 */
314
void DataControlPlugin::showObject( int objectId ) {
315

316 317 318
  if ( ! OpenFlipper::Options::gui())
      return;

319
  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
320 321 322
  if ( PluginFunctions::getObject(objectId,object) ){
    object->show();
  }
Dirk Wilden's avatar
Dirk Wilden committed
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 355 356 357 358 359 360
//******************************************************************************

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

361 362 363
//******************************************************************************

/** \brief Group given Objects together
Jan Möbius's avatar
Jan Möbius committed
364
 *
365 366 367
 * @param _objectIDs list of object ids
 * @param _groupName the name of the new group
 */
Jan Möbius's avatar
Jan Möbius committed
368
int DataControlPlugin::groupObjects(IdList _objectIDs, QString _groupName) {
Dirk Wilden's avatar
Dirk Wilden committed
369 370
  QVector< BaseObject* > objs;

371
  // Try to get all objects given in list
Dirk Wilden's avatar
Dirk Wilden committed
372 373
  for (uint i=0; i < _objectIDs.size(); i++){
    BaseObject* obj;
374
    if ( PluginFunctions::getObject(_objectIDs[i],obj) )
Dirk Wilden's avatar
Dirk Wilden committed
375 376 377
      objs.push_back(obj);
  }

378
  // If all of them fail, stop here.
Dirk Wilden's avatar
Dirk Wilden committed
379
  if (objs.size() == 0){
380
    emit log(tr("No objects to group."));
381
    return -1;
Dirk Wilden's avatar
Dirk Wilden committed
382
  }
383

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

393 394
  }

Dirk Wilden's avatar
Dirk Wilden committed
395
  //create new group
396 397 398
  int groupId = addEmptyGroup(_groupName);
  BaseObject *groupItem = 0;
  PluginFunctions::getObject(groupId, groupItem);
Dirk Wilden's avatar
Dirk Wilden committed
399

400 401 402
  if (parent) {
    groupItem->setParent(parent);
  }
Dirk Wilden's avatar
Dirk Wilden committed
403

404
  IdList ids;
Dirk Wilden's avatar
Dirk Wilden committed
405
  //append new children to group
406 407
  for ( int i = 0 ; i < objs.size() ; ++i)
  {
408
    (objs[i])->setParent(groupItem);
409
    ids.push_back((objs[i])->id());
Dirk Wilden's avatar
Dirk Wilden committed
410
  }
411 412 413

  emit objectsGrouped(ids);
  emit updatedObject(groupId,UPDATE_ALL);
414
  
415
  return groupId;
Dirk Wilden's avatar
Dirk Wilden committed
416
}
417

418 419
//******************************************************************************

420
bool DataControlPlugin::unGroupObject(int _id) {
421
  BaseObject* group = 0;
422
  
423
  PluginFunctions::getObject(_id,group);
424
 
425 426 427 428 429 430 431 432 433 434 435 436
  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() );

437 438
    return true;
  } else {
439 440 441 442
    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) );
443 444 445 446
    return false;
  }
}

447 448 449

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

Dirk Wilden's avatar
Dirk Wilden committed
450
/** \brief Set Target Selection for all objects
Jan Möbius's avatar
Jan Möbius committed
451
 *
452
 */
Dirk Wilden's avatar
Dirk Wilden committed
453
void DataControlPlugin::setAllTarget() {
454 455 456 457 458 459 460 461 462 463

  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) ;
464 465 466
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->target(true);
  }
Dirk Wilden's avatar
Dirk Wilden committed
467 468
}

469 470 471 472

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

/** \brief Set Source Selection for all objects
Jan Möbius's avatar
Jan Möbius committed
473
 *
474
 */
Dirk Wilden's avatar
Dirk Wilden committed
475
void DataControlPlugin::setAllSource() {
476 477 478 479 480 481 482 483 484 485

  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) ;
486 487 488
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->source(true);
  }
Dirk Wilden's avatar
Dirk Wilden committed
489 490
}

491 492 493

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

Jan Möbius's avatar
Jan Möbius committed
494 495
/** \brief Clear Target Selection for all objects
 *
496
 */
Dirk Wilden's avatar
Dirk Wilden committed
497
void DataControlPlugin::clearAllTarget() {
498 499 500 501 502 503 504 505 506 507

  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) ;
508 509 510
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->target(false);
  }
Dirk Wilden's avatar
Dirk Wilden committed
511 512
}

513 514 515 516

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

/** \brief Clear Source Selection for all objects
Jan Möbius's avatar
Jan Möbius committed
517
 *
518
 */
Dirk Wilden's avatar
Dirk Wilden committed
519
void DataControlPlugin::clearAllSource() {
520 521 522 523 524 525 526 527 528 529

  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) ;
530 531 532
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
    o_it->source(false);
  }
Dirk Wilden's avatar
Dirk Wilden committed
533 534
}

535 536 537 538

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

/** \brief Hide all objects
Jan Möbius's avatar
Jan Möbius committed
539
 *
540
 */
Dirk Wilden's avatar
Dirk Wilden committed
541
void DataControlPlugin::hideAll() {
542

543 544 545
  if ( ! OpenFlipper::Options::gui())
      return;

546 547 548 549 550 551 552 553 554
  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) ;
555
                                    o_it != PluginFunctions::objectsEnd(); ++o_it){
Dirk Wilden's avatar
Dirk Wilden committed
556
    o_it->hide();
557 558
  }

Dirk Wilden's avatar
Dirk Wilden committed
559 560
}

561 562 563 564

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

/** \brief Show all objects
Jan Möbius's avatar
Jan Möbius committed
565
 *
566
 */
Dirk Wilden's avatar
Dirk Wilden committed
567
void DataControlPlugin::showAll() {
568

569 570 571
  if ( ! OpenFlipper::Options::gui())
      return;

572 573 574 575 576 577 578 579 580
  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
581
    o_it->show();
582 583
  }

Dirk Wilden's avatar
Dirk Wilden committed
584
}
585 586 587 588 589 590 591 592 593 594 595 596

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

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

598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
  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;  
}

616 617 618 619 620 621
//******************************************************************************

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

623 624 625
  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()));
}
626

627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
//******************************************************************************

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

//******************************************************************************
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661

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

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

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