PluginCommunication.cc 25.6 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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 48 49 50 51 52 53 54 55 56 57




//=============================================================================
//
//  CLASS Core - IMPLEMENTATION of Comunication with plugins
//
//=============================================================================


//== INCLUDES =================================================================

#include "Core.hh"

58
#include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
Martin Schultz's avatar
Martin Schultz committed
59
#include <stdexcept>
60

Jan Möbius's avatar
Jan Möbius committed
61
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
62 63 64

//========================================================================================
// ===             Object List Communication                       =======================
Jan Möbius's avatar
Jan Möbius committed
65 66
//========================================================================================

Jan Möbius's avatar
Jan Möbius committed
67 68 69 70 71
/** \brief Handle object updates by plugins
 *
 * This function is called by a plugin if it changed something in the object list (source,target, or other properties ).
 * The information is passed to all plugins.
 *
Jan Möbius's avatar
 
Jan Möbius committed
72
 * @param _identifier Id of the updated object
73
 * @param _type       What part of the object has been updated
Jan Möbius's avatar
 
Jan Möbius committed
74
 */
75
void Core::slotObjectUpdated(int _identifier, const UpdateType& _type) {
Jan Möbius's avatar
Jan Möbius committed
76 77 78
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
79 80
        emit log(LOGINFO,"updatedObject( " + QString::number(_identifier) + ", " + updateTypeName(_type)
                 + tr(" ) called by ") + QString( sender()->metaObject()->className() ) );
Jan Möbius's avatar
Jan Möbius committed
81
      }
82
    } else {
Dirk Wilden's avatar
Dirk Wilden committed
83
      emit log(LOGINFO,"updatedObject( " + QString::number(_identifier) + ", " + updateTypeName(_type) + tr(" ) called by Core") );
Jan Möbius's avatar
Jan Möbius committed
84 85 86
    }
  }

87 88 89
  // Disable redraws as everything here has to update the object only once
  OpenFlipper::Options::redrawDisabled(true);

90
  // If we are called for a special object, we update it ourself so the Plugins dont need to do that.
91
  BaseObject* object = 0;
92
  if ( _identifier != -1 ) {
Jan Möbius's avatar
 
Jan Möbius committed
93
    if ( !PluginFunctions::getObject(_identifier,object) ) {
94
      emit log(LOGERR,tr("updated_objects called for non existing object with id : ") + QString::number(_identifier) );
95 96 97 98
      return;
    }
  }

99

100 101 102
  // If the identifier is -1 we force an update of all objects in the scene (Bad idea for scenes with many objects)
  if ( _identifier == -1 ) {

103 104 105 106 107 108 109 110
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
        emit log(LOGWARN,"updatedObject( " + QString::number(_identifier) + ", " + updateTypeName(_type)
            + tr(" ) called by ") + QString( sender()->metaObject()->className() + tr(" which is inefficient)") ) );
      }
    } else {
      emit log(LOGWARN,"updatedObject( " + QString::number(_identifier) + ", " + updateTypeName(_type) + tr(" ) called by Core, which is inefficient!") );
    }
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

    for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_ALL ) ;  o_it != PluginFunctions::objectsEnd(); ++o_it) {

      // just inform the plugins as we don't do anything else (Do deprecated and new updatedObjects here)
      emit signalObjectUpdated(o_it->id());
      emit signalObjectUpdated(o_it->id(), _type);

      // Call the objects update function
      o_it->update();

    }
  } else {
    // just inform the plugins as we don't do anything else (Do deprecated and new updatedObjects here)
    emit signalObjectUpdated(_identifier);
    emit signalObjectUpdated(_identifier, _type);
  }


  // If we have an single object, call it's update function
130
  if ( object != 0 )
Dirk Wilden's avatar
Dirk Wilden committed
131
    object->update(_type);
132 133 134 135

  // Reenable redraws
  OpenFlipper::Options::redrawDisabled(false);

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

137 138
  // Reset scenegraph but keep scene center!
  resetScenegraph(false);
139

140
  updateView();
Jan Möbius's avatar
Jan Möbius committed
141 142
}

143
void Core::slotVisibilityChanged( int _id ) {
144

145 146
  // tell plugins
  emit visibilityChanged( _id );
147

148 149 150
  // Reset scenegraph but keep scene center!
  resetScenegraph(false);
  
151
  updateView();
152 153 154 155 156 157
}

/** This function is called if the active object has changed. The information is passed to all plugins.
*/
void Core::slotObjectSelectionChanged( int _id )
{
158
  // just inform the plugins as we don't do anything else
159 160
  emit objectSelectionChanged(_id);

161
  // Send via second interface
Jan Möbius's avatar
Jan Möbius committed
162
  emit signalObjectUpdated(_id,UPDATE_STATE);
163

164
  updateView();
165
}
Jan Möbius's avatar
 
Jan Möbius committed
166

Jan Möbius's avatar
Jan Möbius committed
167 168 169 170 171
void Core::slotObjectPropertiesChanged( int _id )
{
  emit objectPropertiesChanged(_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
172 173 174 175 176
//========================================================================================
// ===             Texture Communication                       ===========================
//========================================================================================


Dirk Wilden's avatar
Dirk Wilden committed
177 178 179 180
/** Called by a plugin if it created a texture. The information is passed to all plugins. If a texture control plugin is available it has to react on the signal.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotAddTexture( QString _textureName , QString _filename, uint _dimension, int _id) {
181 182 183 184 185 186 187 188

  if (QThread::currentThread() != QApplication::instance()->thread())
  {
    //execute method in main thread
    QMetaObject::invokeMethod(this,"slotAddTexture",Qt::BlockingQueuedConnection, Q_ARG(QString, _textureName), Q_ARG(QString, _filename), Q_ARG(uint, _dimension), Q_ARG(int, _id));
    return;
  }

Jan Möbius's avatar
Jan Möbius committed
189 190 191 192 193 194 195 196 197 198 199
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
        emit log(LOGINFO,"addTexture( " + _textureName + "," + _filename + ","  +  QString::number(_dimension) + ", " + QString::number(_id) +  tr(" ) called by ") +
        QString( sender()->metaObject()->className() ) );
      }
    } else {
      emit log(LOGINFO,"addTexture( " + _textureName + "," + _filename + "," +  QString::number(_dimension) + ", " + QString::number(_id) +  tr(" ) called by Core") );
    }
  }
  
Dirk Wilden's avatar
Dirk Wilden committed
200 201 202
  emit addTexture(_textureName , _filename,_dimension,_id);
}

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
/** Called by a plugin if it created a texture. The information is passed to all plugins. If a texture control plugin is available it has to react on the signal.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotAddTexture( QString _textureName , QImage _image, uint _dimension, int _id) {

  if (QThread::currentThread() != QApplication::instance()->thread())
  {
    //execute method in main thread
    QMetaObject::invokeMethod(this,"slotAddTexture",Qt::BlockingQueuedConnection, Q_ARG(QString, _textureName), Q_ARG(QImage, _image), Q_ARG(uint, _dimension), Q_ARG(int, _id));
    return;
  }

  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
        emit log(LOGINFO,"addTexture( " + _textureName + ",QImage,"  +  QString::number(_dimension) + ", " + QString::number(_id) +  tr(" ) called by ") +
        QString( sender()->metaObject()->className() ) );
      }
    } else {
      emit log(LOGINFO,"addTexture( " + _textureName + ",image," +  QString::number(_dimension) + ", " + QString::number(_id) +  tr(" ) called by Core") );
    }
  }
  
  emit addTexture(_textureName , _image,_dimension,_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
229 230 231 232
/** Called by a plugin if it created a texture. The information is passed to all plugins. If a texture control plugin is available it has to react on the signal.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotAddTexture( QString _textureName , QString _filename, uint _dimension) {
Jan Möbius's avatar
Jan Möbius committed
233
  
234 235 236 237 238 239 240
  if (QThread::currentThread() != QApplication::instance()->thread())
  {
    //execute method in main thread
    QMetaObject::invokeMethod(this,"slotAddTexture",Qt::BlockingQueuedConnection, Q_ARG(QString, _textureName), Q_ARG(QString, _filename), Q_ARG(uint, _dimension));
    return;
  }

Jan Möbius's avatar
Jan Möbius committed
241 242 243 244 245 246 247 248 249 250 251
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
        emit log(LOGINFO,"slotAddTexture( " + _textureName + "," + _filename + ","  +  QString::number(_dimension)  +  tr(" ) called by ") +
        QString( sender()->metaObject()->className() ) );
      }
    } else {
      emit log(LOGINFO,"slotAddTexture( " + _textureName + "," + _filename + "," +", " +  QString::number(_dimension) + tr(" ) called by Core") );
    }
  }
  
Jan Möbius's avatar
Jan Möbius committed
252
  emit addTexture(_textureName , _filename,_dimension);
Jan Möbius's avatar
 
Jan Möbius committed
253 254
}

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
/** Called by a plugin if it created a texture. The information is passed to all plugins. If a texture control plugin is available it has to react on the signal.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotAddTexture( QString _textureName , QImage _image, uint _dimension) {
  
  if (QThread::currentThread() != QApplication::instance()->thread())
  {
    //execute method in main thread
    QMetaObject::invokeMethod(this,"slotAddTexture",Qt::BlockingQueuedConnection, Q_ARG(QString, _textureName), Q_ARG(QImage, _image), Q_ARG(uint, _dimension));
    return;
  }

  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
        emit log(LOGINFO,"slotAddTexture( " + _textureName + ",_image,"  +  QString::number(_dimension)  +  tr(" ) called by ") +
        QString( sender()->metaObject()->className() ) );
      }
    } else {
      emit log(LOGINFO,"slotAddTexture( " + _textureName + ",_image," +", " +  QString::number(_dimension) + tr(" ) called by Core") );
    }
  }
  
  emit addTexture(_textureName , _image,_dimension);
}

Jan Möbius's avatar
 
Jan Möbius committed
281 282 283 284
/** Called by a plugin if a texture has to be updated. The information is passed to all plugins. The Plugin providing the given Texture should react on this event.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotUpdateTexture( QString _name , int _identifier){
285 286 287 288

  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
289
        emit log(LOGINFO,"slotUpdateTexture( "  + _name + " , " + QString::number(_identifier) + tr(" ) called by ") +
290 291 292 293 294
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }

Jan Möbius's avatar
Jan Möbius committed
295
  emit updateTexture(_name, _identifier);
Jan Möbius's avatar
 
Jan Möbius committed
296 297
}

298 299 300
void Core::slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int* _textureId ) {
  slotMultiTextureAdded(_textureGroup, _name, _filename, _id, *_textureId);
}
301 302

void Core::slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId ) {
Jan Möbius's avatar
Jan Möbius committed
303
  
304 305 306 307 308 309 310
  if (QThread::currentThread() != QApplication::instance()->thread())
  {
    //execute method in main thread
    QMetaObject::invokeMethod(this,"slotMultiTextureAdded",Qt::BlockingQueuedConnection, Q_ARG(QString, _textureGroup), Q_ARG(QString, _name), Q_ARG(QString, _filename), Q_ARG(int, _id), Q_ARG(int*, &_textureId));
    return;
  }

Jan Möbius's avatar
Jan Möbius committed
311 312 313 314 315 316 317 318 319 320 321
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
        emit log(LOGINFO,"slotMultiTextureAdded( " + _textureGroup + ", " + _name + "," + _filename + ","  + QString::number(_id) + tr(" ) called by ") +
        QString( sender()->metaObject()->className() ) );
      }
    } else {
      emit log(LOGINFO,"slotMultiTextureAdded( " + _textureGroup + ", " + _name + "," + _filename + ","  + QString::number(_id) + tr(" ) called by Core") );
    }
  }
  
322 323 324
  emit addMultiTexture( _textureGroup , _name , _filename , _id , _textureId  );
}

325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
void Core::slotMultiTextureAdded( QString _textureGroup , QString _name , QImage _image , int _id , int& _textureId ) {
  
  if (QThread::currentThread() != QApplication::instance()->thread())
  {
    //execute method in main thread
    QMetaObject::invokeMethod(this,"slotMultiTextureAdded",Qt::BlockingQueuedConnection, Q_ARG(QString, _textureGroup), Q_ARG(QString, _name), Q_ARG(QImage, _image), Q_ARG(int, _id), Q_ARG(int*, &_textureId));
    return;
  }

  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
        emit log(LOGINFO,"slotMultiTextureAdded( " + _textureGroup + ", " + _name + ",_image,"  + QString::number(_id) + tr(" ) called by ") +
        QString( sender()->metaObject()->className() ) );
      }
    } else {
      emit log(LOGINFO,"slotMultiTextureAdded( " + _textureGroup + ", " + _name + ",_image,"  + QString::number(_id) + tr(" ) called by Core") );
    }
  }
  
  emit addMultiTexture( _textureGroup , _name , _image , _id , _textureId  );
}

Jan Möbius's avatar
 
Jan Möbius committed
348 349 350 351
/** Called by a plugin if all textures should be updated. The information is passed to all plugins. All plugins providing textures should react on this event.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotUpdateAllTextures( ){
Jan Möbius's avatar
Jan Möbius committed
352
  emit updateAllTextures();
Jan Möbius's avatar
 
Jan Möbius committed
353 354
}

Dirk Wilden's avatar
Dirk Wilden committed
355 356 357 358 359 360 361 362
/** Called by a plugin if the parameters of a texture should be changed. The information is passed to all plugins. A Texturecontrol plugin should react on this event.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotSetTextureMode(QString _textureName, QString _mode, int _id) {

  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
363
        emit log(LOGINFO,"slotSetTextureMode( " + _textureName + " , " + _mode + " , " + QString::number(_id) + tr(" ) called by ") +
Dirk Wilden's avatar
Dirk Wilden committed
364 365 366 367 368 369 370 371
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }

  emit setTextureMode(_textureName,_mode,_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
372 373 374 375
/** Called by a plugin if the parameters of a texture should be changed. The information is passed to all plugins. A Texturecontrol plugin should react on this event.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotSetTextureMode(QString _textureName ,QString _mode) {
376 377 378 379

  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
380
        emit log(LOGINFO,"slotSetTextureMode( " + _textureName + " , " + _mode + tr(" ) called by ") +
381 382 383 384 385
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }

Jan Möbius's avatar
Jan Möbius committed
386
  emit setTextureMode(_textureName,_mode);
Jan Möbius's avatar
 
Jan Möbius committed
387 388 389 390 391 392
}

/** Called by a plugin if it updated a texture. The information is passed to all plugins. If a texture control plugin is available it has to react on the signal and update the visualization of the texture.\n
 * See in the documentation of the texture plugin interfaces for further detail.
*/
void Core::slotTextureUpdated( QString _textureName , int _identifier ) {
393 394 395
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
396
        emit log(LOGINFO,"slotTextureUpdated( " + _textureName + " , " + QString::number(_identifier) + tr(" ) called by ") +
397 398 399 400
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }
Jan Möbius's avatar
Jan Möbius committed
401
  emit updatedTextures(_textureName,_identifier);
Jan Möbius's avatar
 
Jan Möbius committed
402 403
}

Dirk Wilden's avatar
Dirk Wilden committed
404 405 406 407 408 409
/** Called by plugins if texture mode should be switched
 */
void Core::slotSwitchTexture( QString _textureName, int _id ) {
  emit switchTexture(_textureName, _id);
}

Jan Möbius's avatar
 
Jan Möbius committed
410 411 412 413 414 415
/** Called by plugins if texture mode should be switched
 */
void Core::slotSwitchTexture( QString _textureName ) {
  emit switchTexture(_textureName);
}

416 417 418 419 420 421 422 423 424 425 426 427 428

/** Called by plugins if texture image should be changed
 */
void Core::slotTextureChangeImage( QString _textureName , QImage& _image ) {
  emit textureChangeImage( _textureName ,_image );
}

/** Called by plugins if texture image should be changed
 */
void Core::slotTextureChangeImage( QString _textureName , QImage& _image , int _id )  {
  emit textureChangeImage( _textureName , _image , _id );
}

429 430 431 432 433 434 435 436 437 438 439 440
/** Called by plugins if texture image should be fetched
 */
void Core::slotTextureGetImage( QString _textureName , QImage& _image ) {
  emit textureGetImage( _textureName ,_image );
}

/** Called by plugins if texture image should be fetched
 */
void Core::slotTextureGetImage( QString _textureName , QImage& _image , int _id )  {
  emit textureGetImage( _textureName , _image , _id );
}

441 442 443 444 445 446
/** Called by plugins if texture index should be fetched
 */
void Core::slotTextureIndex( QString _textureName, int _id, int& _index){
  emit textureIndex( _textureName, _id, _index);
}

447 448 449 450 451 452
/** Called by plugins if texture index property name should be fetched
 */
void Core::slotTextureIndexPropertyName( int _id, QString& _propertyName){
  emit textureIndexPropertyName( _id, _propertyName);
}

453 454 455 456 457 458
/** Called by plugins if texture name should be fetched
 */
void Core::slotTextureName( int _id, int _textureIndex, QString& _textureName){
  emit textureName( _id, _textureIndex, _textureName);
}

459 460 461 462 463 464
/** Called by plugins if texture filename should be fetched
 */
void Core::slotTextureFilename( int _id, QString _textureName, QString& _textureFilename){
  emit textureFilename( _id, _textureName, _textureFilename);
}

465 466 467 468 469 470 471 472 473 474 475 476
/** Called by plugins if current texture name should be returned
 */
void Core::slotGetCurrentTexture( int _id, QString& _textureName ){
  emit getCurrentTexture( _id, _textureName );
}

/** Called by plugins if texture image should be fetched
 */
void Core::slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures ){
  emit getSubTextures( _id, _multiTextureName, _subTextures );
}

Jan Möbius's avatar
Jan Möbius committed
477 478 479
//========================================================================================
// ===            Object Manager                              ============================
//========================================================================================
Jan Möbius's avatar
 
Jan Möbius committed
480

Jan Möbius's avatar
Jan Möbius committed
481 482
/// This slot is called by the object manager when a new object is created
void Core::newObject(int _objectId) {
483
  
484 485 486 487
   BaseObject* baseObject = 0;
   PluginFunctions::getObject(_objectId,baseObject);
   
   if ( baseObject ) {
488 489 490
    connect( baseObject, SIGNAL(visibilityChanged(int)),       this, SLOT(slotVisibilityChanged(int)),       Qt::DirectConnection) ;
    connect( baseObject, SIGNAL(objectSelectionChanged(int)),  this, SLOT(slotObjectSelectionChanged(int)),  Qt::DirectConnection );
    connect( baseObject, SIGNAL(objectPropertiesChanged(int)), this, SLOT(slotObjectPropertiesChanged(int)), Qt::DirectConnection );
491 492
   } else {
     emit log(LOGERR,tr("newObject received from objectManager with invalid id! This should not happen. The new Object will not work correctly!"));
493 494
   }
   
Jan Möbius's avatar
Jan Möbius committed
495
}
Jan Möbius's avatar
 
Jan Möbius committed
496

Jan Möbius's avatar
Jan Möbius committed
497
/// This slot is called by the object manager when a object is deleted
Dirk Wilden's avatar
Dirk Wilden committed
498
void Core::deletedObject(int /*_objectId*/) {
Jan Möbius's avatar
Jan Möbius committed
499 500
}

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

502 503 504
//========================================================================================
// ===            Cross Plugin connections                    ============================
//========================================================================================
505 506 507 508

/// Helper function to avoid code duplication
void connectPlugins( Core* c, const std::vector<PluginInfo>& plugins_, QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot, bool _queued)
{
509 510
  QObject* plugin1 = 0;
  QObject* plugin2 = 0;
511

Jan Möbius's avatar
Jan Möbius committed
512 513 514
  for ( int i = 0 ; i < (int)plugins_.size(); ++i ) {
    if ( plugins_[i].rpcName == _pluginName1 ) {
      plugin1 = plugins_[i].plugin;
515
    }
Jan Möbius's avatar
Jan Möbius committed
516 517
    if ( plugins_[i].rpcName == _pluginName2 ) {
      plugin2 = plugins_[i].plugin;
518 519 520 521
    }
  }

  if (  plugin1 == 0 ) {
522
    emit c->log(LOGERR,QObject::tr("Cross Plugin Interconnection failed because plugin %1 was not found!").arg(_pluginName1));
523 524 525 526
    return;
  }

  if (  plugin2 == 0 ) {
527
    emit c->log(LOGERR,QObject::tr("Cross Plugin Interconnection failed because plugin %1 was not found!").arg(_pluginName2));
528 529
    return;
  }
530

531
  // now connect them
532 533 534 535 536 537 538
  if(_queued)
    QObject::connect(plugin1,_signal,plugin2,_slot, Qt::QueuedConnection);
  else
    QObject::connect(plugin1,_signal,plugin2,_slot);
}

void Core::slotCrossPluginConnect( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) {
539
  connectPlugins(this, plugins(), _pluginName1,  _signal, _pluginName2, _slot, false);
540 541 542
}

void Core::slotCrossPluginConnectQueued( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) {
543
  connectPlugins(this, plugins(), _pluginName1,  _signal, _pluginName2, _slot, true);
544 545
}

546 547 548 549 550 551
//========================================================================================
// ===            Renderer Settings                    ============================
//========================================================================================
void Core::slotSetRenderer(unsigned int _viewer, QString _rendererName) {
  renderManager().setActive(_rendererName,_viewer);
}
Jan Möbius's avatar
 
Jan Möbius committed
552

Jan Möbius's avatar
Jan Möbius committed
553 554 555 556
void Core::slotGetCurrentRenderer(unsigned int _viewer, QString& _rendererName) {
  _rendererName = renderManager().active(_viewer)->name;
}

557 558 559 560 561 562 563 564 565 566 567
void Core::slotMetadataDeserialized(
        const QVector<QPair<QString, QString> > &data) {

    QString obj_metadata;
    for (QVector<QPair<QString, QString> >::const_iterator
            it = data.begin(); it != data.end(); ++it) {
        if (it->first == "Mesh Comments")
            obj_metadata = it->second;

        emit genericMetadataDeserialized(it->first, it->second);
    }
Jan Möbius's avatar
Jan Möbius committed
568

569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
    /*
     * Now handle object metadata.
     */
    QRegExp re_begin("BEGIN Comments for object \"([^\\n]*)\"");
    QRegExp re_end("\\nEND Comments for object \"([^\\n]*)\"");
    enum STATE {
        STATE_SEARCH_BEGIN,
        STATE_CONSUME_INNER,
        STATE_EOS,
    };

    int cursor = 0;
    QString current_object_name;
    for (STATE state = STATE_SEARCH_BEGIN; state != STATE_EOS; ) {
        switch (state) {
            case STATE_SEARCH_BEGIN:
                cursor = re_begin.indexIn(obj_metadata, cursor);
                if (cursor == -1) {
                    state = STATE_EOS;
                    break;
                }
                current_object_name = re_begin.cap(1);
                cursor += re_begin.matchedLength();
                state = STATE_CONSUME_INNER;
                break;
            case STATE_CONSUME_INNER:
            {
                int next = re_end.indexIn(obj_metadata, cursor);
                if (next == -1) {
                    state = STATE_EOS;
                    break;
                }

                const QStringRef value = obj_metadata.midRef(cursor, next - cursor);

                emit objectMetadataDeserialized(current_object_name, value.toString());
                QJsonParseError json_error;
                QJsonDocument json_doc =
                        QJsonDocument::fromJson(value.toUtf8(), &json_error);
                if (json_error.error == QJsonParseError::NoError) {
                    emit objectMetadataDeserializedJson(
                            current_object_name, json_doc);
                }
                cursor = next + re_end.matchedLength();
                state = STATE_SEARCH_BEGIN;
                break;
            }
            default:
                throw std::logic_error("metadataDeserialized(): Invalid state.");
        }
    }
}
Jan Möbius's avatar
Jan Möbius committed
621

Jan Möbius's avatar
 
Jan Möbius committed
622
//=============================================================================