PluginCommunication.cc 17.2 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
51
52
53
54
55
56
57
58
59
60
61
62




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


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

#include "Core.hh"

#include <QToolBox>

#include "OpenFlipper/BasePlugin/BaseInterface.hh"
#include "OpenFlipper/BasePlugin/ToolboxInterface.hh"
#include "OpenFlipper/BasePlugin/TextureInterface.hh"

63
#include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
64

65
66
#include <OpenFlipper/common/RendererInfo.hh>

Jan Möbius's avatar
Jan Möbius committed
67
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
68
69
70

//========================================================================================
// ===             Object List Communication                       =======================
Jan Möbius's avatar
Jan Möbius committed
71
72
//========================================================================================

Jan Möbius's avatar
 
Jan Möbius committed
73
74
75
/** This function is called by a plugin if it changed something in the object list (source,target,...). The information is passed to all plugins.
 * @param _identifier Id of the updated object
 */
76
void Core::slotObjectUpdated(int _identifier, const UpdateType& _type) {
Jan Möbius's avatar
Jan Möbius committed
77
78
79
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
80
81
        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
82
      }
83
    } else {
Dirk Wilden's avatar
Dirk Wilden committed
84
      emit log(LOGINFO,"updatedObject( " + QString::number(_identifier) + ", " + updateTypeName(_type) + tr(" ) called by Core") );
Jan Möbius's avatar
Jan Möbius committed
85
86
87
    }
  }

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

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

100
  // just inform the plugins as we dont do anything else (Do deprecated and new updatedObjects here)
101
  emit signalObjectUpdated(_identifier);
Dirk Wilden's avatar
Dirk Wilden committed
102
  emit signalObjectUpdated(_identifier, _type);
103

104
  if ( object != 0 )
Dirk Wilden's avatar
Dirk Wilden committed
105
    object->update(_type);
106
107
108
109

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

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

111
112
  // Reset scenegraph but keep scene center!
  resetScenegraph(false);
113

114
  updateView();
Jan Möbius's avatar
Jan Möbius committed
115
116
}

117
void Core::slotVisibilityChanged( int _id ) {
118

119
120
  // tell plugins
  emit visibilityChanged( _id );
121

122
123
124
  // Reset scenegraph but keep scene center!
  resetScenegraph(false);
  
125
  updateView();
126
127
128
129
130
131
}

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

135
  // Send via second interface
Jan Möbius's avatar
Jan Möbius committed
136
  emit signalObjectUpdated(_id,UPDATE_STATE);
137

138
  updateView();
139
}
Jan Möbius's avatar
 
Jan Möbius committed
140

Jan Möbius's avatar
Jan Möbius committed
141
142
143
144
145
void Core::slotObjectPropertiesChanged( int _id )
{
  emit objectPropertiesChanged(_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
146
147
148
149
150
//========================================================================================
// ===             Texture Communication                       ===========================
//========================================================================================


Dirk Wilden's avatar
Dirk Wilden committed
151
152
153
154
/** 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) {
Jan Möbius's avatar
Jan Möbius committed
155
156
157
158
159
160
161
162
163
164
165
  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
166
167
168
  emit addTexture(_textureName , _filename,_dimension,_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
169
170
171
172
/** 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
173
174
175
176
177
178
179
180
181
182
183
184
  
  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
185
  emit addTexture(_textureName , _filename,_dimension);
Jan Möbius's avatar
 
Jan Möbius committed
186
187
188
189
190
191
}

/** 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){
192
193
194
195

  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
196
        emit log(LOGINFO,"slotUpdateTexture( "  + _name + " , " + QString::number(_identifier) + tr(" ) called by ") +
197
198
199
200
201
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }

Jan Möbius's avatar
Jan Möbius committed
202
  emit updateTexture(_name, _identifier);
Jan Möbius's avatar
 
Jan Möbius committed
203
204
}

205
206

void Core::slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId ) {
Jan Möbius's avatar
Jan Möbius committed
207
208
209
210
211
212
213
214
215
216
217
218
  
  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") );
    }
  }
  
219
220
221
  emit addMultiTexture( _textureGroup , _name , _filename , _id , _textureId  );
}

Jan Möbius's avatar
 
Jan Möbius committed
222
223
224
225
/** 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
226
  emit updateAllTextures();
Jan Möbius's avatar
 
Jan Möbius committed
227
228
}

Dirk Wilden's avatar
Dirk Wilden committed
229
230
231
232
233
234
235
236
/** 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 ) {
237
        emit log(LOGINFO,"slotSetTextureMode( " + _textureName + " , " + _mode + " , " + QString::number(_id) + tr(" ) called by ") +
Dirk Wilden's avatar
Dirk Wilden committed
238
239
240
241
242
243
244
245
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }

  emit setTextureMode(_textureName,_mode,_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
246
247
248
249
/** 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) {
250
251
252
253

  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
254
        emit log(LOGINFO,"slotSetTextureMode( " + _textureName + " , " + _mode + tr(" ) called by ") +
255
256
257
258
259
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }

Jan Möbius's avatar
Jan Möbius committed
260
  emit setTextureMode(_textureName,_mode);
Jan Möbius's avatar
 
Jan Möbius committed
261
262
263
264
265
266
}

/** 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 ) {
267
268
269
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
270
        emit log(LOGINFO,"slotTextureUpdated( " + _textureName + " , " + QString::number(_identifier) + tr(" ) called by ") +
271
272
273
274
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }
Jan Möbius's avatar
Jan Möbius committed
275
  emit updatedTextures(_textureName,_identifier);
Jan Möbius's avatar
 
Jan Möbius committed
276
277
}

Dirk Wilden's avatar
Dirk Wilden committed
278
279
280
281
282
283
/** 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
284
285
286
287
288
289
/** Called by plugins if texture mode should be switched
 */
void Core::slotSwitchTexture( QString _textureName ) {
  emit switchTexture(_textureName);
}

290
291
292
293
294
295
296
297
298
299
300
301
302

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

303
304
305
306
307
308
309
310
311
312
313
314
/** 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 );
}

315
316
317
318
319
320
/** Called by plugins if texture index should be fetched
 */
void Core::slotTextureIndex( QString _textureName, int _id, int& _index){
  emit textureIndex( _textureName, _id, _index);
}

321
322
323
324
325
326
/** Called by plugins if texture index property name should be fetched
 */
void Core::slotTextureIndexPropertyName( int _id, QString& _propertyName){
  emit textureIndexPropertyName( _id, _propertyName);
}

327
328
329
330
331
332
/** Called by plugins if texture name should be fetched
 */
void Core::slotTextureName( int _id, int _textureIndex, QString& _textureName){
  emit textureName( _id, _textureIndex, _textureName);
}

333
334
335
336
337
338
/** Called by plugins if texture filename should be fetched
 */
void Core::slotTextureFilename( int _id, QString _textureName, QString& _textureFilename){
  emit textureFilename( _id, _textureName, _textureFilename);
}

339
340
341
342
343
344
345
346
347
348
349
350
/** 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
351
352
353
//========================================================================================
// ===            Object Manager                              ============================
//========================================================================================
Jan Möbius's avatar
 
Jan Möbius committed
354

Jan Möbius's avatar
Jan Möbius committed
355
356
/// This slot is called by the object manager when a new object is created
void Core::newObject(int _objectId) {
357
  
358
359
360
361
   BaseObject* baseObject = 0;
   PluginFunctions::getObject(_objectId,baseObject);
   
   if ( baseObject ) {
362
363
364
    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 );
365
366
   } else {
     emit log(LOGERR,tr("newObject received from objectManager with invalid id! This should not happen. The new Object will not work correctly!"));
367
368
   }
   
Jan Möbius's avatar
Jan Möbius committed
369
}
Jan Möbius's avatar
 
Jan Möbius committed
370

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

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

376
377
378
379
380
381
382
//========================================================================================
// ===            Cross Plugin connections                    ============================
//========================================================================================
void Core::slotCrossPluginConnect( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) {
  QObject* plugin1 = 0;
  QObject* plugin2 = 0;
  
Jan Möbius's avatar
Jan Möbius committed
383
384
385
  for ( int i = 0 ; i < (int)plugins_.size(); ++i ) {
    if ( plugins_[i].rpcName == _pluginName1 ) {
      plugin1 = plugins_[i].plugin;
386
    }
Jan Möbius's avatar
Jan Möbius committed
387
388
    if ( plugins_[i].rpcName == _pluginName2 ) {
      plugin2 = plugins_[i].plugin;
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
    }
  }

  if (  plugin1 == 0 ) {
    emit log(LOGERR,tr("Cross Plugin Interconnection failed because plugin %1 was not found!").arg(_pluginName1)); 
    return;
  }

  if (  plugin2 == 0 ) {
    emit log(LOGERR,tr("Cross Plugin Interconnection failed because plugin %1 was not found!").arg(_pluginName2)); 
    return;
  }
  
  // now connect them
  connect(plugin1,_signal,plugin2,_slot);
}

406
407
408
409
410
411
//========================================================================================
// ===            Renderer Settings                    ============================
//========================================================================================
void Core::slotSetRenderer(unsigned int _viewer, QString _rendererName) {
  renderManager().setActive(_rendererName,_viewer);
}
Jan Möbius's avatar
 
Jan Möbius committed
412

Jan Möbius's avatar
Jan Möbius committed
413
414
415
416
void Core::slotGetCurrentRenderer(unsigned int _viewer, QString& _rendererName) {
  _rendererName = renderManager().active(_viewer)->name;
}

Jan Möbius's avatar
Jan Möbius committed
417
418


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