PluginCommunication.cc 10.7 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
Jan Möbius's avatar
Jan Möbius committed
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16
17
18
19
//  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.
Jan Möbius's avatar
Jan Möbius committed
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




//=============================================================================
//
//  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"

52
53
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"

Jan Möbius's avatar
Jan Möbius committed
54
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
55
56
57

//========================================================================================
// ===             Object List Communication                       =======================
Jan Möbius's avatar
Jan Möbius committed
58
59
//========================================================================================

Jan Möbius's avatar
 
Jan Möbius committed
60
61
62
/** 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
 */
63
void Core::slotObjectUpdated(int _identifier) {
Jan Möbius's avatar
Jan Möbius committed
64
65
66
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
67
        emit log(LOGINFO,"updatedObject( " + QString::number(_identifier) + " ) called by " +
Jan Möbius's avatar
Jan Möbius committed
68
69
                 QString( sender()->metaObject()->className() ) );
      }
70
71
    } else {
      emit log(LOGINFO,"updatedObject( " + QString::number(_identifier) + " ) called by Core" );
Jan Möbius's avatar
Jan Möbius committed
72
73
74
    }
  }

75
76
77
  // Disable redraws as everything here has to update the object only once
  OpenFlipper::Options::redrawDisabled(true);

78
  // If we are called for a special object, we update it ourself so the Plugins dont need to do that.
79
  BaseObject* object = 0;
80
  if ( _identifier != -1 ) {
Jan Möbius's avatar
   
Jan Möbius committed
81
    if ( !PluginFunctions::getObject(_identifier,object) ) {
82
83
84
85
86
      emit log(LOGERR,"updated_objects called for non existing object with id : " + QString::number(_identifier) );
      return;
    }
  }

Jan Möbius's avatar
Jan Möbius committed
87
  // just inform the plugins as we dont do anything else
88
  emit signalObjectUpdated(_identifier);
89

90
91
  if ( object != 0 )
    object->update();
92
93
94
95

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

Jan Möbius's avatar
Jan Möbius committed
96
97
98

  // TODO: full reset is not required here. It should at least keep the scene center!
  resetScenegraph();
99

100
  updateView();
Jan Möbius's avatar
Jan Möbius committed
101
102
}

103
void Core::slotVisibilityChanged( int _id ) {
104

105
106
  // tell plugins
  emit visibilityChanged( _id );
107
108

  updateView();
109
110
111
112
113
114
115
116
117
118
119
120
}

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

//   std::cerr << "objectSelection changed triggers updatedObjects for now" << std::endl;
//   emit updatedObject(_id);
}
Jan Möbius's avatar
 
Jan Möbius committed
121

Jan Möbius's avatar
Jan Möbius committed
122
123
124
125
126
void Core::slotObjectPropertiesChanged( int _id )
{
  emit objectPropertiesChanged(_id);
}

Jan Möbius's avatar
Jan Möbius committed
127
//====================================================================================
Jan Möbius's avatar
 
Jan Möbius committed
128
129
// ===             Toolbox handling                                   =================
//=====================================================================================
Jan Möbius's avatar
Jan Möbius committed
130

Jan Möbius's avatar
 
Jan Möbius committed
131
132
133
134
135
136
137
 /** If the Toolbox is switched the toolboxActivated function of the each plugin that has a toolbox is called by this function.
  */
// void
// Core::slotToolboxSwitched(int _index)
// {
//    // Check all plugins
//    for ( uint i = 0 ; i < plugins.size(); ++i) {
Jan Möbius's avatar
Jan Möbius committed
138
//       if (plugins[i].toolboxindex == -1)
Jan Möbius's avatar
 
Jan Möbius committed
139
//          continue;
Jan Möbius's avatar
Jan Möbius committed
140
//
Jan Möbius's avatar
 
Jan Möbius committed
141
142
143
//       ToolboxInterface* toolboxPlugin = qobject_cast< ToolboxInterface * >(plugins[i].plugin);
//       if (! toolboxPlugin)
//          continue;
Jan Möbius's avatar
Jan Möbius committed
144
//
Jan Möbius's avatar
 
Jan Möbius committed
145
146
//       // Call the corresponding function of the plugins
//       if ( _index == plugins[i].toolboxindex ) {
Jan Möbius's avatar
Jan Möbius committed
147
//            toolboxPlugin->toolboxActivated(true);
Jan Möbius's avatar
 
Jan Möbius committed
148
//       } else {
Jan Möbius's avatar
Jan Möbius committed
149
//            toolboxPlugin->toolboxActivated(false);
Jan Möbius's avatar
 
Jan Möbius committed
150
151
152
153
154
155
156
157
158
//       }
//    }
// }

//========================================================================================
// ===             Texture Communication                       ===========================
//========================================================================================


Dirk Wilden's avatar
Dirk Wilden committed
159
160
161
162
163
164
165
/** 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) {
  emit addTexture(_textureName , _filename,_dimension,_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
166
167
168
169
/** 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
170
  emit addTexture(_textureName , _filename,_dimension);
Jan Möbius's avatar
 
Jan Möbius committed
171
172
173
174
175
176
}

/** 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){
177
178
179
180
181
182
183
184
185
186

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

Jan Möbius's avatar
Jan Möbius committed
187
  emit updateTexture(_name, _identifier);
Jan Möbius's avatar
 
Jan Möbius committed
188
189
}

190
191
192
193
194

void Core::slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId ) {
  emit addMultiTexture( _textureGroup , _name , _filename , _id , _textureId  );
}

Jan Möbius's avatar
 
Jan Möbius committed
195
196
197
198
/** 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
199
  emit updateAllTextures();
Jan Möbius's avatar
 
Jan Möbius committed
200
201
}

Dirk Wilden's avatar
Dirk Wilden committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/** 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 ) {
        emit log(LOGINFO,"slotSetTextureMode( " + _textureName + " , " + _mode + " , " + QString::number(_id) + " ) called by " +
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }

  emit setTextureMode(_textureName,_mode,_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
219
220
221
222
/** 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) {
223
224
225
226
227
228
229
230
231
232

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

Jan Möbius's avatar
Jan Möbius committed
233
  emit setTextureMode(_textureName,_mode);
Jan Möbius's avatar
 
Jan Möbius committed
234
235
236
237
238
239
}

/** 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 ) {
240
241
242
243
244
245
246
247
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
        emit log(LOGINFO,"slotTextureUpdated( " + _textureName + " , " + QString::number(_identifier) + " ) called by " +
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }
Jan Möbius's avatar
Jan Möbius committed
248
  emit updatedTextures(_textureName,_identifier);
Jan Möbius's avatar
 
Jan Möbius committed
249
250
}

Dirk Wilden's avatar
Dirk Wilden committed
251
252
253
254
255
256
/** 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
257
258
259
260
261
262
/** Called by plugins if texture mode should be switched
 */
void Core::slotSwitchTexture( QString _textureName ) {
  emit switchTexture(_textureName);
}

263
264
265
266
267
268
269
270
271
272
273
274
275

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

Jan Möbius's avatar
 
Jan Möbius committed
276
277
278
279
280
281
//========================================================================================
// ===             Backup Communication                       ============================
//========================================================================================

/// Called if a backup is requested by the plugins
void Core::backupRequest( int _id , QString _name ) {
Jan Möbius's avatar
Jan Möbius committed
282
283
  emit createBackup(  _id , _name , nextBackupId_);
  ++nextBackupId_;
Jan Möbius's avatar
 
Jan Möbius committed
284
285
286
287
288
289
290
}





//=============================================================================