PluginCommunication.cc 12.5 KB
Newer Older
1 2 3 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 39 40 41
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           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/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
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 64
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"

Jan Möbius's avatar
Jan Möbius committed
65
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
66 67 68

//========================================================================================
// ===             Object List Communication                       =======================
Jan Möbius's avatar
Jan Möbius committed
69 70
//========================================================================================

Jan Möbius's avatar
 
Jan Möbius committed
71 72 73
/** 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
 */
74
void Core::slotObjectUpdated(int _identifier) {
Jan Möbius's avatar
Jan Möbius committed
75 76 77
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
78
        emit log(LOGINFO,"updatedObject( " + QString::number(_identifier) + tr(" ) called by ") +
Jan Möbius's avatar
Jan Möbius committed
79 80
                 QString( sender()->metaObject()->className() ) );
      }
81
    } else {
82
      emit log(LOGINFO,"updatedObject( " + QString::number(_identifier) + tr(" ) called by Core") );
Jan Möbius's avatar
Jan Möbius committed
83 84 85
    }
  }

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

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

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

101 102
  if ( object != 0 )
    object->update();
103 104 105 106

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

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

108 109
  // Reset scenegraph but keep scene center!
  resetScenegraph(false);
110

111
  updateView();
Jan Möbius's avatar
Jan Möbius committed
112 113
}

114
void Core::slotVisibilityChanged( int _id ) {
115

116 117
  // tell plugins
  emit visibilityChanged( _id );
118

119 120 121
  // Reset scenegraph but keep scene center!
  resetScenegraph(false);
  
122
  updateView();
123 124 125 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 )
{
  // just inform the plugins as we dont do anything else
  emit objectSelectionChanged(_id);

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

Jan Möbius's avatar
Jan Möbius committed
137 138 139 140 141
void Core::slotObjectPropertiesChanged( int _id )
{
  emit objectPropertiesChanged(_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
142 143 144 145 146
//========================================================================================
// ===             Texture Communication                       ===========================
//========================================================================================


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

/** 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){
165 166 167 168

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

Jan Möbius's avatar
Jan Möbius committed
175
  emit updateTexture(_name, _identifier);
Jan Möbius's avatar
 
Jan Möbius committed
176 177
}

178 179 180 181 182

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
183 184 185 186
/** 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
187
  emit updateAllTextures();
Jan Möbius's avatar
 
Jan Möbius committed
188 189
}

Dirk Wilden's avatar
Dirk Wilden committed
190 191 192 193 194 195 196 197
/** 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 ) {
198
        emit log(LOGINFO,"slotSetTextureMode( " + _textureName + " , " + _mode + " , " + QString::number(_id) + tr(" ) called by ") +
Dirk Wilden's avatar
Dirk Wilden committed
199 200 201 202 203 204 205 206
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }

  emit setTextureMode(_textureName,_mode,_id);
}

Jan Möbius's avatar
 
Jan Möbius committed
207 208 209 210
/** 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) {
211 212 213 214

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

Jan Möbius's avatar
Jan Möbius committed
221
  emit setTextureMode(_textureName,_mode);
Jan Möbius's avatar
 
Jan Möbius committed
222 223 224 225 226 227
}

/** 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 ) {
228 229 230
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
231
        emit log(LOGINFO,"slotTextureUpdated( " + _textureName + " , " + QString::number(_identifier) + tr(" ) called by ") +
232 233 234 235
                 QString( sender()->metaObject()->className() ) );
      }
    }
  }
Jan Möbius's avatar
Jan Möbius committed
236
  emit updatedTextures(_textureName,_identifier);
Jan Möbius's avatar
 
Jan Möbius committed
237 238
}

Dirk Wilden's avatar
Dirk Wilden committed
239 240 241 242 243 244
/** 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
245 246 247 248 249 250
/** Called by plugins if texture mode should be switched
 */
void Core::slotSwitchTexture( QString _textureName ) {
  emit switchTexture(_textureName);
}

251 252 253 254 255 256 257 258 259 260 261 262 263

/** 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
264 265 266 267 268 269
//========================================================================================
// ===             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
270 271
  emit createBackup(  _id , _name , nextBackupId_);
  ++nextBackupId_;
Jan Möbius's avatar
 
Jan Möbius committed
272 273
}

Jan Möbius's avatar
Jan Möbius committed
274 275 276
//========================================================================================
// ===            Object Manager                              ============================
//========================================================================================
Jan Möbius's avatar
 
Jan Möbius committed
277

Jan Möbius's avatar
Jan Möbius committed
278 279
/// This slot is called by the object manager when a new object is created
void Core::newObject(int _objectId) {
280
  
281 282 283 284
   BaseObject* baseObject = 0;
   PluginFunctions::getObject(_objectId,baseObject);
   
   if ( baseObject ) {
285 286
    connect( baseObject, SIGNAL(visibilityChanged(int)),     this, SLOT(slotVisibilityChanged(int)), Qt::DirectConnection) ;
    connect( baseObject, SIGNAL(objectSelectionChanged(int)),this, SLOT(slotObjectSelectionChanged(int)), Qt::DirectConnection );
287 288
   } else {
     emit log(LOGERR,tr("newObject received from objectManager with invalid id! This should not happen. The new Object will not work correctly!"));
289 290
   }
   
Jan Möbius's avatar
Jan Möbius committed
291
}
Jan Möbius's avatar
 
Jan Möbius committed
292 293 294



Jan Möbius's avatar
Jan Möbius committed
295 296


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