Core.cc 80.5 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73





//=============================================================================
//
//  CLASS Core - IMPLEMENTATION
//
//=============================================================================


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

// -------------------- mview
#include "Core.hh"
// -------------------- ACG

#include <ACG/QtWidgets/QtFileDialog.hh>
// -------------------- Qt


#include "OpenFlipper/BasePlugin/KeyInterface.hh"
#include "OpenFlipper/BasePlugin/MouseInterface.hh"
#include "OpenFlipper/BasePlugin/PickingInterface.hh"
#include "OpenFlipper/BasePlugin/ToolboxInterface.hh"
#include "OpenFlipper/BasePlugin/TextureInterface.hh"
#include "OpenFlipper/BasePlugin/INIInterface.hh"

#include <OpenFlipper/common/RecentFiles.hh>

Jan Möbius's avatar
 
Jan Möbius committed
74
#include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
Jan Möbius's avatar
 
Jan Möbius committed
75

Jan Möbius's avatar
Jan Möbius committed
76 77
#include "OpenFlipper/BasePlugin/RPCWrappers.hh"

Jan Möbius's avatar
 
Jan Möbius committed
78 79
#include <OpenMesh/Core/System/omstream.hh>

80 81
#include <OpenFlipper/common/BaseObjectCore.hh>
#include <OpenFlipper/common/TypesInternal.hh>
Jan Möbius's avatar
Jan Möbius committed
82

Isaak Lim's avatar
Isaak Lim committed
83 84
#include <OpenFlipper/widgets/messageBox/StaysOnTopMessageBox.hh>

85 86
#include <OpenFlipper/common/PluginStorage.hh>

87 88 89
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>

90 91 92 93
#ifdef PYTHON_ENABLED
  #include <PythonInterpreter/PythonInterpreter.hh>
#endif

Jan Möbius's avatar
 
Jan Möbius committed
94 95 96
#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH  800

97
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
98 99

/** \brief Constuctor for the Core Widget ( This is stage 1 , call init for stage 2)
100
 *
Jan Möbius's avatar
 
Jan Möbius committed
101 102 103 104 105 106 107 108 109
 * Initialization is working the following way:\n
 * - Setup basic paths \n
 * - Get Options from Option files ( While skipping the OpenFiles Sections as Core is not running )\n
 * - Jump back ( Stage two is done by calling init from main ) so CALL init!!
 * - This Two stage system allows using commandline options which override Option Files
*/
Core::
Core() :
  QObject(),
110
  capture_(false),
111
  processManager_(0),
Jan Möbius's avatar
 
Jan Möbius committed
112
  nextBackupId_(0),
Dirk Wilden's avatar
Dirk Wilden committed
113
  nextBackupGroupId_(0),
114
  objectRoot_(0),
115 116
  coreWidget_(0),
  splash_(0)
Jan Möbius's avatar
 
Jan Möbius committed
117
{
118

Dirk Wilden's avatar
Dirk Wilden committed
119 120 121 122
  //init logFile
  logStream_ = 0;
  logFile_ = 0;

Dirk Wilden's avatar
Dirk Wilden committed
123 124
  //init nodes
  root_node_scenegraph_ = new ACG::SceneGraph::SeparatorNode(0, "SceneGraph Root Node");
Jan Möbius's avatar
Jan Möbius committed
125
  
126
  // init global data node
Jan Möbius's avatar
Jan Möbius committed
127
  root_node_scenegraph_global_ = new ACG::SceneGraph::SeparatorNode(root_node_scenegraph_ , "SceneGraph Rendered Root Node");
128
  
Jan Möbius's avatar
Jan Möbius committed
129
  // This separator will manage the cores nodes
130
  core_nodes_ = new ACG::SceneGraph::SeparatorNode(root_node_scenegraph_global_, "Core Nodes");
Jan Möbius's avatar
Jan Möbius committed
131 132 133 134
  
  // Coordsys rendering nodes
  coordsysMaterialNode_ = new ACG::SceneGraph::MaterialNode(core_nodes_,"Coordsys Material Node");
  coordsysNode_ = new ACG::SceneGraph::CoordsysNode(coordsysMaterialNode_,"Core Coordsys Node");  
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
135
  coordsysNode_->setTraverseMode (BaseNode::NodeFirst | BaseNode::SecondPass);
Jan Möbius's avatar
Jan Möbius committed
136
  
Jan Möbius's avatar
Jan Möbius committed
137
  // Separator handling the nodes for data
138
  dataSeparatorNode_ = new ACG::SceneGraph::SeparatorNode(root_node_scenegraph_global_, "Data Separator Root Node");
Jan Möbius's avatar
Jan Möbius committed
139
  
Jan Möbius's avatar
Jan Möbius committed
140
  // Separator handling the nodes for data
Jan Möbius's avatar
Jan Möbius committed
141
  dataRootNode_      = new ACG::SceneGraph::SeparatorNode(dataSeparatorNode_, "Data Root Node");
Dirk Wilden's avatar
Dirk Wilden committed
142

Jan Möbius's avatar
 
Jan Möbius committed
143 144 145
   // Add ViewMode All
  ViewMode* vm = new ViewMode();
  vm->name = "All";
Jan Möbius's avatar
Jan Möbius committed
146
  vm->icon = "viewmode_all.png";
Jan Möbius's avatar
 
Jan Möbius committed
147
  vm->custom = false;
Jan Möbius's avatar
Jan Möbius committed
148
  vm->visibleToolboxes = QStringList();
149

Jan Möbius's avatar
 
Jan Möbius committed
150 151
  viewModes_.push_front(vm);

Dirk Wilden's avatar
Dirk Wilden committed
152 153 154
  //init ViewerProperties (always for 4 Viewers!)
  std::vector< Viewer::ViewerProperties* > viewerProperties;

155
  for (int i=0; i < 4; i++) {
156
    Viewer::ViewerProperties* viewerProperty = new Viewer::ViewerProperties(i);
157 158 159
    viewerProperty->snapshotBaseFileName("snap-Viewer-" + QString::number(i) + ".png");
    viewerProperties.push_back( viewerProperty );
  }
Dirk Wilden's avatar
Dirk Wilden committed
160 161 162

  PluginFunctions::setViewerProperties(viewerProperties);

163 164 165 166 167 168
  //set viewer defaults
  OpenFlipper::Options::defaultViewingDirection( PluginFunctions::VIEW_FREE,  0 );
  OpenFlipper::Options::defaultViewingDirection( PluginFunctions::VIEW_TOP,   1 );
  OpenFlipper::Options::defaultViewingDirection( PluginFunctions::VIEW_LEFT,  2 );
  OpenFlipper::Options::defaultViewingDirection( PluginFunctions::VIEW_FRONT, 3 );

Jan Möbius's avatar
 
Jan Möbius committed
169 170
  // Get all relevant Paths and Options from option files
  setupOptions();
Jan Möbius's avatar
Jan Möbius committed
171

172 173
  // set discriptions for scriptable slots
  setDescriptions();
174 175 176
  
  // Initialize the build in dataTypes
  initializeTypes();
Dirk Wilden's avatar
Dirk Wilden committed
177 178 179
  
  // Initialize the build in updateTypes
  initializeUpdateTypes();
Jan Möbius's avatar
 
Jan Möbius committed
180 181
}

182 183 184
/** \brief Second initialization stage
 *
 * This Stage does the following :\n
Jan Möbius's avatar
 
Jan Möbius committed
185 186 187 188 189 190
 * - Create the Core GUI Elements (Examiner, Toolbox,...)\n
 * - Create the MenuBar \n
 * - load the Plugins \n
 * - connect the Mouse slots \n
 * - Load all ini files (This includes the Global Option files) \n
 */
191 192
void
Core::init() {
Jan Möbius's avatar
Jan Möbius committed
193 194 195
  
  // Check library versions
  checkLibraryVersions();
196

Jan Möbius's avatar
 
Jan Möbius committed
197
  // Make root_node available to the plugins ( defined in PluginFunctions.hh)
Jan Möbius's avatar
Jan Möbius committed
198
  PluginFunctions::setDataSeparatorNodes( dataSeparatorNode_ );
199

200
  // Topmost node of the scenegraph
Jan Möbius's avatar
 
Jan Möbius committed
201
  PluginFunctions::setSceneGraphRootNode( root_node_scenegraph_ );
202 203 204 205
  
  // Node below the global status nodes. All nodes with global rendering
  // will be attached here.
  PluginFunctions::setSceneGraphRootNodeGlobal(root_node_scenegraph_global_);
Dirk Wilden's avatar
Dirk Wilden committed
206

Jan Möbius's avatar
 
Jan Möbius committed
207
  // Initialize the first object as the root Object for the object tree
208
  objectRoot_ =  dynamic_cast< BaseObject* > ( new GroupObject("ObjectRoot") );
Jan Möbius's avatar
 
Jan Möbius committed
209
  PluginFunctions::setDataRoot( objectRoot_ );
Jan Möbius's avatar
Jan Möbius committed
210 211 212
  
  // Bring up the object manager ( has to be done after the rootobject is created)
  connect(getObjectManager(),SIGNAL(newObject(int)), this ,SLOT(newObject(int)));
213 214
  
  connect(getObjectManager(),SIGNAL(deletedObject(int)), this ,SLOT(deletedObject(int)));
215

Jan Möbius's avatar
 
Jan Möbius committed
216
  if ( OpenFlipper::Options::gui() ) {
217

Jan Möbius's avatar
Jan Möbius committed
218
    // Initialize redraw timer. Will be used to restrict the rendering framerate.
219 220 221 222
    redrawTimer_ = new QTimer();
    redrawTimer_->setSingleShot(true);
    connect(redrawTimer_, SIGNAL(timeout()), this, SLOT(updateView()),Qt::DirectConnection);

223 224 225 226 227 228
    // Initialice scenegraph check timer. Will be used to check for changes in the scenegraph
    scenegraphCheckTimer_ = new QTimer();
    scenegraphCheckTimer_->setSingleShot(false);
    connect(scenegraphCheckTimer_, SIGNAL(timeout()), this, SLOT(checkScenegraphDirty()),Qt::DirectConnection);

    // Will measure the time between redraws
Jan's avatar
Jan committed
229
    redrawTime_ = new QElapsedTimer();
230
    redrawTime_->start ();
231

232
    if ( OpenFlipperSettings().value("Core/Gui/splash",true).toBool() ) {
Jan Möbius's avatar
 
Jan Möbius committed
233
      QPixmap splashPixmap(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "splash.png");
234

235
      splash_ = new QSplashScreen(splashPixmap, Qt::SplashScreen | Qt::WindowStaysOnTopHint);
Jan Möbius's avatar
 
Jan Möbius committed
236
      splash_->show();
237

238
      splash_->showMessage(tr("Initializing mainwindow") ,
Jan Möbius's avatar
 
Jan Möbius committed
239 240
                          Qt::AlignBottom | Qt::AlignLeft , Qt::white);
    }
241

242
    coreWidget_ = new CoreWidget(viewModes_ , coreSlots_);
243

244 245 246 247
    spinBoxEventFilter_.registerScrollArea(coreWidget_->getToolboxScrollArea());
    spinBoxEventFilter_.registerScrollArea(coreWidget_->getToolboxArea());
    spinBoxEventFilter_.registerScrollArea(coreWidget_->getToolbox());

Jan Möbius's avatar
 
Jan Möbius committed
248
    connect(coreWidget_, SIGNAL(clearAll())           , this, SLOT(clearAll()));
249
    connect(coreWidget_, SIGNAL(loadMenu())           , this, SLOT(loadObject()));
Jan Möbius's avatar
 
Jan Möbius committed
250
    connect(coreWidget_, SIGNAL(addEmptyObjectMenu()) , this, SLOT(slotAddEmptyObjectMenu()));
251 252 253 254
    connect(coreWidget_, SIGNAL(saveMenu())           , this, SLOT(saveAllObjects()));
    connect(coreWidget_, SIGNAL(saveToMenu())         , this, SLOT(saveAllObjectsTo()));
    connect(coreWidget_, SIGNAL(loadIniMenu())        , this, SLOT(loadSettings()));
    connect(coreWidget_, SIGNAL(saveIniMenu())        , this, SLOT(saveSettings()));
255
    connect(coreWidget_, SIGNAL(applyOptions())       , this, SLOT(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
256
    connect(coreWidget_, SIGNAL(saveOptions())        , this, SLOT(saveOptions()));
Jan Möbius's avatar
 
Jan Möbius committed
257
    connect(coreWidget_, SIGNAL(recentOpen(QAction*)) , this, SLOT(slotRecentOpen(QAction*)));
258
    connect(coreWidget_, SIGNAL(exit())               , this, SLOT(slotExit()), Qt::QueuedConnection); // queue to avoid destroying the core widget during event handling
259

260 261 262

    connect( coreWidget_, SIGNAL( resizeViewers(int,int) ), this, SLOT( resizeViewers(int,int) ) );
    connect( coreWidget_, SIGNAL( resizeApplication(int,int) ), this, SLOT( resizeApplication(int,int) ) );
Dirk Wilden's avatar
Dirk Wilden committed
263 264
    connect( coreWidget_, SIGNAL( stopVideoCapture() ), this, SLOT( stopVideoCapture() ) );
    connect( coreWidget_, SIGNAL( startVideoCapture(QString,int,bool) ), this, SLOT( startVideoCapture(QString,int,bool) ) );
265
    connect( coreWidget_, SIGNAL( dragOpenFile(QString)), this, SLOT(loadObject(QString)));
266

Dirk Wilden's avatar
Dirk Wilden committed
267
    connect(coreWidget_, SIGNAL(showPlugins())       , this, SLOT(slotShowPlugins()));
268

Dirk Wilden's avatar
Dirk Wilden committed
269
    connect(coreWidget_, SIGNAL(call(QString,bool&)), this, SLOT(slotCall(QString,bool&)));
270 271
    
    connect( coreWidget_->logWidget_->openMeshFilterAction_,SIGNAL(toggled(bool)), this, SLOT(enableOpenMeshErrorLog(bool)) );
Dirk Wilden's avatar
Dirk Wilden committed
272

Jan's avatar
Jan committed
273 274
    QScreen *screen = QGuiApplication::primaryScreen();
    QRect  rect = screen->geometry();
Jan Möbius's avatar
Jan Möbius committed
275 276 277 278 279 280 281 282 283 284 285

    uint width = rect.width();
    if ( width > 1000 ) {
      width = 1000;
    }

    uint height = rect.height();
    if ( height > 1000 ) {
      height = 1000;
    }

Jan Möbius's avatar
Jan Möbius committed
286 287 288
#ifdef ARCH_DARWIN
    width = rect.width() - 300;
    height = rect.height() - 150;
Jan Möbius's avatar
Jan Möbius committed
289

Jan Möbius's avatar
Jan Möbius committed
290
//     coreWidget_->setMaximumSize( width, height  );
Jan Möbius's avatar
Jan Möbius committed
291 292
#endif

Jan Möbius's avatar
Jan Möbius committed
293
    coreWidget_->resize(width,height);
294 295


Jan Möbius's avatar
Jan Möbius committed
296 297 298
    // Sanity check for OpenGL capabilities!
    checkOpenGLCapabilities();

Jan Möbius's avatar
Jan Möbius committed
299 300 301 302

    QString titleInfo = OpenFlipper::Options::windowTitle();

    #ifdef DEBUG
303
      titleInfo = titleInfo + " [DEBUG]";
Jan Möbius's avatar
Jan Möbius committed
304 305 306 307 308 309 310 311 312
    #endif

    if ( OpenFlipper::Options::coreProfile() )
      titleInfo = titleInfo + " CoreProfile";
    else
      titleInfo = titleInfo + " CompatProfile";

    coreWidget_->setWindowTitle( titleInfo );

Jan Möbius's avatar
 
Jan Möbius committed
313
  }
314

Jan Möbius's avatar
 
Jan Möbius committed
315 316 317 318
  // ======================================================================
  // Create intermediate logger class for Core which will mangle the output
  // ======================================================================
  PluginLogger* newlog = new PluginLogger("Core");
319

Jan Möbius's avatar
 
Jan Möbius committed
320 321
  loggers_.push_back(newlog);
  connect(this,SIGNAL(log(Logtype, QString )),newlog,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
322 323
  connect(this,SIGNAL(log(QString )),newlog,SLOT(slotLog(QString )),Qt::DirectConnection);

Jan Möbius's avatar
 
Jan Möbius committed
324 325 326
  // Connect it to the Master logger
  if ( OpenFlipper::Options::gui() )
    connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
327

Jan Möbius's avatar
 
Jan Möbius committed
328
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
329

Dirk Wilden's avatar
Dirk Wilden committed
330 331
  // connection to file logger
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
332 333 334 335 336 337 338

  // ======================================================================
  // Create a logger class for CoreWidget
  // ======================================================================

  if ( OpenFlipper::Options::gui() ){
    PluginLogger* widgetlog = new PluginLogger("CoreWidget");
339

Dirk Wilden's avatar
Dirk Wilden committed
340 341
    loggers_.push_back(widgetlog);
    connect(coreWidget_,SIGNAL(log(Logtype, QString )),widgetlog,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
342 343
    connect(coreWidget_,SIGNAL(log(QString )),widgetlog,SLOT(slotLog(QString )),Qt::DirectConnection);

Dirk Wilden's avatar
Dirk Wilden committed
344 345 346
    // Connect it to the Master logger
    connect(widgetlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
    connect(widgetlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
347 348
    // connection to file logger
    connect(widgetlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
349
  }
350

Jan Möbius's avatar
 
Jan Möbius committed
351 352 353 354 355 356
  // ======================================================================
  // Catch OpenMesh Error logs with an own Logger
  // ======================================================================
  newlog = new PluginLogger("Core ( OpenMesh )",LOGERR);
  omerr().connect(*newlog);
  omerr().disconnect(std::cerr);
357

Jan Möbius's avatar
 
Jan Möbius committed
358
  loggers_.push_back(newlog);
359

Jan Möbius's avatar
 
Jan Möbius committed
360 361 362
  // Connect it to the Master logger
  if ( OpenFlipper::Options::gui() )
    connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
363

Jan Möbius's avatar
 
Jan Möbius committed
364
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
365 366
  // connection to file logger
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
367

Jan Möbius's avatar
 
Jan Möbius committed
368 369 370 371 372 373
  // ======================================================================
  // Catch OpenMesh omout logs with an own Logger
  // ======================================================================
  newlog = new PluginLogger("Core ( OpenMesh )",LOGINFO);
  omout().connect(*newlog);
  omout().disconnect(std::cout);
374

Jan Möbius's avatar
 
Jan Möbius committed
375
  loggers_.push_back(newlog);
376

Jan Möbius's avatar
 
Jan Möbius committed
377 378 379
  // Connect it to the Master logger
  if ( OpenFlipper::Options::gui() )
    connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
380

Jan Möbius's avatar
 
Jan Möbius committed
381
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
382 383
  // connection to file logger
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
384

Jan Möbius's avatar
 
Jan Möbius committed
385 386 387 388 389
  // ======================================================================
  // Catch OpenMesh omlog logs with an own Logger
  // ======================================================================
  newlog = new PluginLogger("Core ( OpenMesh )",LOGOUT);
  omlog().connect(*newlog);
390

Jan Möbius's avatar
 
Jan Möbius committed
391
  loggers_.push_back(newlog);
392

Jan Möbius's avatar
 
Jan Möbius committed
393 394 395
  // Connect it to the Master logger
  if ( OpenFlipper::Options::gui() )
    connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
396

Jan Möbius's avatar
 
Jan Möbius committed
397
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
398 399
  // connection to file logger
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
400

Jan Möbius's avatar
 
Jan Möbius committed
401 402 403 404
  // ======================================================================
  // Log Scripting stuff through a separate logger
  // ======================================================================
  newlog = new PluginLogger("Scripting",LOGOUT);
405

Jan Möbius's avatar
 
Jan Möbius committed
406
  loggers_.push_back(newlog);
407

Jan Möbius's avatar
 
Jan Möbius committed
408 409 410
  // Connect it to the Master logger
  if ( OpenFlipper::Options::gui() )
    connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
411

Jan Möbius's avatar
 
Jan Möbius committed
412
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
413
  // connection to file logger
414
  connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
Dirk Wilden's avatar
Dirk Wilden committed
415

Jan Möbius's avatar
 
Jan Möbius committed
416
  // connect signal to logger
417 418
  connect(this,SIGNAL(scriptLog(QString )),newlog,SLOT(slotLog(QString )),Qt::DirectConnection);

419
  
Jan Möbius's avatar
 
Jan Möbius committed
420
  // ======================================================================
421
  // Set up QtScript Environment
Jan Möbius's avatar
 
Jan Möbius committed
422
  // ======================================================================
423
  
Jan Möbius's avatar
Jan Möbius committed
424 425 426
  // Set a reference to the scriptengine for simple rpc calls
  RPC::setScriptEngine(&scriptEngine_);

Jan Möbius's avatar
Jan Möbius committed
427
  connect(&scriptEngine_, SIGNAL( signalHandlerException(const QScriptValue &) ), this, SLOT( slotScriptError(const QScriptValue &) ));
428

Jan Möbius's avatar
 
Jan Möbius committed
429 430
  // process Events every 500 msecs during script execution
  scriptEngine_.setProcessEventsInterval( 500 );
431

Jan Möbius's avatar
 
Jan Möbius committed
432 433 434 435
  // Register own print function :
  QScriptValue printFunction = scriptEngine_.newFunction(myPrintFunction);
  printFunction.setProperty("textedit",scriptEngine_.newQObject(this));
  scriptEngine_.globalObject().setProperty("print", printFunction);
436

437 438 439
  // Register print to file function :
  QScriptValue printToFileFunc = scriptEngine_.newFunction(printToFileFunction);
  scriptEngine_.globalObject().setProperty("printToFile", printToFileFunc);
440
  scriptingFunctions_.push_back( "-.printToFile(QString,QString)" );
441

Jan Möbius's avatar
Jan Möbius committed
442 443 444 445 446 447
  // Register help function :
  QScriptValue helpFunc = scriptEngine_.newFunction(helpFunction);
  helpFunc.setProperty("core",scriptEngine_.newQObject(this));
  scriptEngine_.globalObject().setProperty("help", helpFunc);
  scriptingFunctions_.push_back( "-.help(QString)" );

448 449 450 451 452 453 454 455 456
  // Register IdList Type to scripting Engine
  qScriptRegisterSequenceMetaType< IdList >(&scriptEngine_);
  
  // Register Vector of ints Type to scripting Engine
  qScriptRegisterSequenceMetaType< QVector< int > >(&scriptEngine_);
  
  //==========================================================================
  // Register the 3d Vector Type to the core ( is Vec3d )
  //==========================================================================
457 458
  qScriptRegisterMetaType(&scriptEngine_,
                          toScriptValueVector,
Jan Möbius's avatar
 
Jan Möbius committed
459 460
                          fromScriptValueVector,
                          scriptEngine_.newQObject(&vec3dPrototype_));
461
                          
Jan Möbius's avatar
 
Jan Möbius committed
462
  // set a constructor to allow creation via Vector(x,y,z)
Jan Möbius's avatar
Jan Möbius committed
463 464 465 466 467 468 469
  QScriptValue ctorVec3 = scriptEngine_.newFunction(createVector);
  scriptEngine_.globalObject().setProperty("Vector", ctorVec3);

  //==========================================================================
  // Register the 4d Vector Type to the core ( is Vec4d )
  //==========================================================================
  qScriptRegisterMetaType(&scriptEngine_,
470 471
                          toScriptValueVector4,
                          fromScriptValueVector4,
Jan Möbius's avatar
Jan Möbius committed
472 473 474 475 476
                          scriptEngine_.newQObject(&vec4dPrototype_));

  // set a constructor to allow creation via Vector(x,y,z)
  QScriptValue ctorVec4 = scriptEngine_.newFunction(createVector4);
  scriptEngine_.globalObject().setProperty("Vector4", ctorVec4);
477 478 479 480
                          
  //==========================================================================
  // Register the DataType Class to the core
  //==========================================================================
481

482
  // Register DataType in QScriptEngine
483
  qScriptRegisterMetaType<DataType>(&scriptEngine_,
484 485 486 487 488
                          toScriptValueDataType,
                          fromScriptValueDataType,
                          scriptEngine_.newQObject(&DataTypePrototype_));
                          
  // set a constructor to allow creation via DataType(uint)
489 490 491 492 493 494
  QScriptValue dataTypector = scriptEngine_.newFunction(createDataType);
  scriptEngine_.globalObject().setProperty("DataType", dataTypector);     
  
  //==========================================================================
  // Register the Matrix Class to the core
  //==========================================================================
495

Jan Möbius's avatar
 
Jan Möbius committed
496
  // Register Matrix Type to scripting Engine ( is ACG::Matrix4x4d )
497 498
  qScriptRegisterMetaType(&scriptEngine_,
                          toScriptValueMatrix4x4 ,
Jan Möbius's avatar
 
Jan Möbius committed
499 500
                          fromScriptValueMatrix4x4,
                          scriptEngine_.newQObject(&matrix4x4Prototype_));
501

Jan Möbius's avatar
 
Jan Möbius committed
502 503 504
  // set a constructor to allow creation via Matrix(x,y,z)
  QScriptValue matrix4x4ctor = scriptEngine_.newFunction(createMatrix4x4);
  scriptEngine_.globalObject().setProperty("Matrix4x4", matrix4x4ctor);
505

506 507 508 509
  //==========================================================================
  //  Collect Core scripting information
  //==========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
510 511 512 513 514 515
  QScriptValue scriptInstance = scriptEngine_.newQObject(this,
                                                         QScriptEngine::QtOwnership,
                                                         QScriptEngine::ExcludeChildObjects |
                                                         QScriptEngine::ExcludeSuperClassMethods |
                                                         QScriptEngine::ExcludeSuperClassProperties
                                                         );
516

Jan Möbius's avatar
 
Jan Möbius committed
517
  scriptEngine_.globalObject().setProperty("core", scriptInstance);
518

Jan Möbius's avatar
 
Jan Möbius committed
519 520 521
  QScriptValueIterator it(scriptInstance);
  while (it.hasNext()) {
    it.next();
522

Jan Möbius's avatar
 
Jan Möbius committed
523
    /// Skip all signals for function calls
524
    if ( checkSignal( this, it.name().toLatin1() ) )
Jan Möbius's avatar
 
Jan Möbius committed
525
      continue;
526

Jan Möbius's avatar
 
Jan Möbius committed
527
    scriptingFunctions_.push_back( "core." + it.name() );
528

Jan Möbius's avatar
 
Jan Möbius committed
529
  }
530

Jan Möbius's avatar
 
Jan Möbius committed
531
  loadPlugins();
532

Jan Möbius's avatar
 
Jan Möbius committed
533
  if ( OpenFlipper::Options::gui() ) {
534

Dirk Wilden's avatar
Dirk Wilden committed
535 536 537
    //register keyBinding for all scripting slots
    coreWidget_->slotRegisterSlotKeyBindings();

538 539 540
    //get keyAssignments from config files
    restoreKeyBindings();

Jan Möbius's avatar
Marlin:  
Jan Möbius committed
541 542
    if ( OpenFlipper::Options::currentViewMode( ) != "" )
      coreWidget_->setViewMode( OpenFlipper::Options::currentViewMode() );
Jan Möbius's avatar
 
Jan Möbius committed
543 544
    else
      coreWidget_->setViewMode("All");
545

546
    // Set the renderer to the one stored in the settings or to default
547
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
Jan Möbius's avatar
Jan Möbius committed
548 549 550 551
      connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalMouseEvent(QMouseEvent*)),
              this                              , SLOT(slotMouseEvent(QMouseEvent*)));
      connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalMouseEventIdentify(QMouseEvent*)),
              this                              , SLOT(slotMouseEventIdentify(QMouseEvent*)));
Jan Möbius's avatar
Mike:  
Jan Möbius committed
552 553
      connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalMouseEventLight(QMouseEvent*)),
              this                              , SLOT(slotMouseEventLight(QMouseEvent*)));
Jan Möbius's avatar
Jan Möbius committed
554 555
      connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalWheelEvent(QWheelEvent *, const std::string &)),
              this                              , SLOT(slotWheelEvent(QWheelEvent *, const std::string &)));
Jan Möbius's avatar
Jan Möbius committed
556 557

      connect( coreWidget_->examiner_widgets_[i], SIGNAL( viewUpdated() ),
558
               this, SLOT( viewUpdated()) ,Qt::DirectConnection);
559

560
      connect( coreWidget_->examiner_widgets_[i], SIGNAL( viewChanged() ),
561
               coreWidget_->examiner_widgets_[i], SLOT( updateGL() ) ,Qt::DirectConnection);
562

Jan Möbius's avatar
Jan Möbius committed
563 564 565
      // Set post processor
      PostProcessorDialog::loadSavedPostProcessors(i);

566 567 568 569 570
      // ====================================================
      // Set renderer
      // ====================================================


571 572
      // Choose one of the two possible renderers. Shader Pipeline for Core Profile or Classical for Compatibility Profile
      QString rendererDefault;
573

574 575 576 577
      if ( OpenFlipper::Options::coreProfile() )
        rendererDefault = "Shader Pipeline Renderer Plugin";
      else
        rendererDefault = "Default Classical Renderer Plugin";
578

579 580 581 582
      // Try to get a default renderer Name from the settings file. If it's not there, we fall back to the default set above
      // based on the current OpenGL Profile
      QString rendererKey  = "Viewer" + QString::number(i)+"/DefaultRenderer";
      QString rendererName = OpenFlipperSettings().value(rendererKey,rendererDefault).toString();
583

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
      // Check if the renderer is there. If a setting was in the options file, we try it here. Otherwise we are checking the default one.
      int rendererId = renderManager().getRendererId(rendererName);

      if ( rendererId == -1 ) {

        // That failed. So either the one stored in the settings is not available or our default failed.
        emit log(LOGERR,tr("Stored default renderer \"") + rendererName + tr("\" is not available, trying") + rendererDefault + "!");

        // Anyway, lets try the default fallback:
        rendererId = renderManager().getRendererId(rendererDefault);

        // Successful?
        if ( rendererId != -1 ) {
          // Lets set it as the active one
          renderManager().setActive(rendererId,i);
599
        } else {
600
          emit log(LOGERR,rendererDefault + tr(" renderer is also not available. Trying to use any other renderer i can find!"));
601 602 603 604

          // debug information for this case, print renderer count and their names
          const unsigned int rendererCount = renderManager().available();
          emit log(LOGERR,tr("Currently ") + QString::number(rendererCount) + tr(" renderers are available:") );
Jan Möbius's avatar
Jan Möbius committed
605 606
          for (unsigned int rendererId = 0 ; rendererId < rendererCount ; ++rendererId )
            emit log(LOGERR, tr("Renderer ") + QString::number(rendererId) + ": " + renderManager()[rendererId]->name );
607 608
        }
      } else {
609
        renderManager().setActive(rendererId,i);
610 611
      }

612

613 614 615 616
    }

    // Warn the user in the log and via messagebox, that he is using the build in renderer only
    if ( renderManager().available() == 1 ) {
617
      finishSplash();
618 619 620 621
      emit log(LOGERR,tr("No external plugin renderers available!"));
      emit log(LOGERR,tr("The build in renderer is only a very limited one and is missing many features!"));
      emit log(LOGERR,tr("You should build and use the other renderers!"));

Isaak Lim's avatar
Isaak Lim committed
622
      StaysOnTopMessageBox::warning(0,tr( "No external plugin renderers available!"),tr("The build in renderer is only a very limited one and is missing many features.\nYou should build and use the other free renderers shipped with OpenFlipper."));
Jan Möbius's avatar
Jan Möbius committed
623
    }
624

Jan Möbius's avatar
 
Jan Möbius committed
625
  }
626

Jan Möbius's avatar
Jan Möbius committed
627 628 629 630
  // ===============================================================================================
  // Load Settings from configuration files
  // ===============================================================================================

Jan Möbius's avatar
 
Jan Möbius committed
631 632
  QStringList optionFiles = OpenFlipper::Options::optionFiles();
  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
633

634
    if (splash_) {
635
      splash_->showMessage(tr("Loading Configuration File %1/%2").arg(i+1).arg(optionFiles.size()),
Jan Möbius's avatar
 
Jan Möbius committed
636 637
                           Qt::AlignBottom | Qt::AlignLeft , Qt::white);
    }
638

Jan Möbius's avatar
Jan Möbius committed
639 640
    // Load global ini files. Use only plugin global options from these files as the
    // rest has been loaded at the beginning.
641 642 643
    if ( OpenFlipper::Options::gui() )
      coreWidget_->updateRecent();

Jan Möbius's avatar
Jan Möbius committed
644
    openIniFile( optionFiles[i] ,false,true,false);
Jan Möbius's avatar
 
Jan Möbius committed
645 646
  }

647
  if (splash_)
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
648
      splash_->clearMessage();
649

Jan Möbius's avatar
Jan Möbius committed
650 651 652
  // ===============================================================================================
  // Load Settings from configuration files
  // ===============================================================================================
653

Jan Möbius's avatar
 
Jan Möbius committed
654
  if ( OpenFlipper::Options::lang().contains("UTF") || OpenFlipper::Options::lang().contains("utf") ) {
655
    emit log(LOGWARN,tr("UTF8-Locale used!"));
Jan Möbius's avatar
Jan Möbius committed
656 657 658 659
//     emit log(LOGWARN,"Only OFF files are fully supported with UTF8. Others might fail.");
//     emit log(LOGWARN,"You can change your locale by :");
//     emit log(LOGWARN,"export LANG=C");
//     emit log(LOGWARN,"Work is in progress to resolve this issue.");
660
  }
Jan Möbius's avatar
 
Jan Möbius committed
661 662

  if ( OpenFlipper::Options::gui() ) {
Dirk Wilden's avatar
Dirk Wilden committed
663

664
    QFile statesFile(OpenFlipper::Options::configDirStr()  + OpenFlipper::Options::dirSeparator() + "WindowStates.dat");
Dirk Wilden's avatar
Dirk Wilden committed
665

666 667
    if (statesFile.exists() ) {
      QSettings windowStates(OpenFlipper::Options::configDirStr()  + OpenFlipper::Options::dirSeparator() + "WindowStates.dat", QSettings::IniFormat);
668

669 670 671 672
      //try to restore the windowState
      coreWidget_->restoreState (windowStates.value("Core/Window/State").toByteArray ());
      //try to restore the geometry
      coreWidget_->restoreGeometry (windowStates.value("Core/Window/Geometry").toByteArray ());
Dirk Wilden's avatar
Dirk Wilden committed
673

674 675
      coreWidget_->toolSplitter_->restoreState (windowStates.value("Core/ToolSplitter").toByteArray ());
      coreWidget_->splitter_->restoreState (windowStates.value("Core/LogSplitter").toByteArray ());
676

677
      coreWidget_->show();
678

679 680 681 682 683 684 685 686 687
      applyOptions();

      windowStates.beginGroup ("Core");
      windowStates.beginGroup ("LogSlider");
      coreWidget_->slidingLogger_->restoreState (windowStates);
      windowStates.endGroup ();
      coreWidget_->toolBox_->restoreState (windowStates);
      windowStates.endGroup ();

688 689 690 691 692

      // Restore if window was maximized or not
      if ( windowStates.value("Core/Window/WindowState",false).toBool() )
        coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowMaximized  );

693 694 695
    } else {

      coreWidget_->show();
696

697 698 699
      applyOptions();

    }
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
700

701
    if ( splash_ ) {
Jan Möbius's avatar
Jan Möbius committed
702
        splash_->raise();
703
        splash_->showMessage(tr("Ready."), Qt::AlignBottom | Qt::AlignLeft , Qt::white);
704
        finishSplash();
Jan Möbius's avatar
 
Jan Möbius committed
705
    }
706

707
    // start checking for scenegraph changes
708
    scenegraphCheckTimer_->setInterval (1000 / OpenFlipperSettings().value("Core/Gui/glViewer/maxFrameRate",35).toInt() );
709
    scenegraphCheckTimer_->start ();
Jan Möbius's avatar
 
Jan Möbius committed
710
  }
711

712 713 714
  // System is ready now.
  OpenFlipper::Options::finishedStartup();
  
Jan Möbius's avatar
Jan Möbius committed
715
  QTimer::singleShot(100, this, SLOT(slotExecuteAfterStartup()));
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742

  // Initialize and connect the logging of the Python interpreter to the core logging facilities

#ifdef PYTHON_ENABLED
  PythonInterpreter* interpreter = PythonInterpreter::getInstance();

  PluginLogger* pythonLog = new PluginLogger("PythonInterpreter");

  loggers_.push_back(pythonLog);

  // Connect input from python interpreter to wrapping logger
  connect(interpreter,SIGNAL(log(Logtype,QString)),pythonLog,SLOT(slotLog(Logtype,QString)),Qt::DirectConnection);

  // connect output to file logger
  connect(pythonLog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);

  // Connect output to the Master loggers
  if ( OpenFlipper::Options::gui())
    connect(pythonLog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);

  connect(pythonLog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);



  std::cerr << "Connected logger!!! " << std::endl;
#endif

Jan Möbius's avatar
 
Jan Möbius committed
743 744
}

745

Jan Möbius's avatar
 
Jan Möbius committed
746 747 748 749
//-----------------------------------------------------------------------------

Core::~Core()
{
750

751 752 753 754 755
  // Delete the objectRoot if it was constructed
  if ( objectRoot_ != 0 ) {
    objectRoot_->deleteSubtree();
    delete objectRoot_;
  }
756

Jan Möbius's avatar
 
Jan Möbius committed
757
  // Clean up loggers
758 759 760
  for ( uint i = 0 ; i < loggers_.size(); ++i )
    delete loggers_[i];

Jan Möbius's avatar
Jan Möbius committed
761
  delete coreWidget_;
Jan Möbius's avatar
 
Jan Möbius committed
762 763 764 765
}

//-----------------------------------------------------------------------------

766 767 768 769 770 771
std::vector<PluginInfo>& Core::plugins()  {
  return PluginStorage::plugins();
};

//-----------------------------------------------------------------------------

Jan Möbius's avatar
 
Jan Möbius committed
772 773 774
void
Core::slotMouseEventIdentify( QMouseEvent* _event )
{
Dirk Wilden's avatar
Dirk Wilden committed
775 776 777
//   // Dont do anything as a context Menu will popup on right button click
//   if ( _event->button() == Qt::RightButton )
//     return;
778

779 780
  // Only catch left-button clicks
  if(_event->button() != Qt::LeftButton) return;
781
  if(_event->type() != QEvent::MouseButtonRelease) return;
782

Jan Möbius's avatar
Jan Möbius committed
783 784 785 786 787 788 789 790 791
  const QObject* senderPointer = sender();
  unsigned int examinerId = 0;

  if ( senderPointer == 0 ) {
    std::cerr << "Error : slotMouseEventIdentify directly called! This should only be called by an examiner" << std::endl;
  } else {
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
      if ( senderPointer == coreWidget_->examiner_widgets_[i] ) {
        examinerId = i;
792
        if ( OpenFlipper::Options::doSlotDebugging() )
793
              emit log(LOGINFO,tr("slotMouseEventIdentify from examiner ") + QString::number(i) );
Jan Möbius's avatar
Jan Möbius committed
794 795 796 797 798 799 800 801
        break;
      }
    }

  }

  PluginFunctions::setActiveExaminer( examinerId );

802
  // Do picking
803
  size_t   node_idx, target_idx;
804 805 806
  ACG::Vec3d     hit_point;

  if(PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING, _event->pos(), node_idx, target_idx, &hit_point)) {
Jan Möbius's avatar
Jan Möbius committed
807

808
    BaseObjectData* object = 0;
Jan Möbius's avatar
Jan Möbius committed
809

810 811 812 813 814 815 816 817
    if(PluginFunctions::getPickedObject(node_idx, object)) {
      // Request type information widget
      InformationInterface* infoPlugin = 0;
      infoPlugin = getInfoPlugin(object->dataType());
      if(infoPlugin != 0)
          infoPlugin->slotInformationRequested(_event->pos(), object->dataType());
    }
  }
Jan Möbius's avatar
 
Jan Möbius committed
818 819 820
}

//-----------------------------------------------------------------------------
Jan Möbius's avatar
Mike:  
Jan Möbius committed
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849

void
Core::slotMouseEventLight( QMouseEvent* _event )
{
  const QObject* senderPointer = sender();
  unsigned int examinerId = 0;

  if ( senderPointer == 0 ) {
    std::cerr << "Error : slotMouseEventLight directly called! This should only be called by an examiner" << std::endl;
  } else {
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
      if ( senderPointer == coreWidget_->examiner_widgets_[i] ) {
        examinerId = i;
        if ( OpenFlipper::Options::doSlotDebugging() )
              emit log(LOGINFO,tr("slotMouseEventLight from examiner ") + QString::number(i) );
        break;
      }
    }

  }

  PluginFunctions::setActiveExaminer( examinerId );

  emit PluginMouseEventLight( _event );


}

//-----------------------------------------------------------------------------
Jan Möbius's avatar
 
Jan Möbius committed
850 851 852 853 854


void
Core::slotMouseEvent( QMouseEvent* _event )
{
Dirk Wilden's avatar
Dirk Wilden committed
855 856 857
//   // Dont do anything as a context Menu will popup on right button click
//   if ( _event->button() == Qt::RightButton )
//     return;
858

Jan Möbius's avatar
Jan Möbius committed
859 860 861 862 863 864 865 866 867
  const QObject* senderPointer = sender();
  unsigned int examinerId = 0;

  if ( senderPointer == 0 ) {
    std::cerr << "Error : slotMouseEvent directly called! This should only be called by an examiner" << std::endl;
  } else {
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
      if ( senderPointer == coreWidget_->examiner_widgets_[i] ) {
        examinerId = i;
868
        if ( OpenFlipper::Options::doSlotDebugging() ) {
869
          QString message = tr("slotMouseEvent from examiner ") + QString::number(i) + " with ";
870 871 872 873 874 875 876 877 878 879

          if ( _event->type() == QEvent::MouseButtonRelease )
            message += " MouseButtonRelease";
          else if ( _event->type() == QEvent::MouseButtonPress )
            message += " MouseButtonRelease";
          else if ( _event->type() == QEvent::MouseButtonDblClick )
            message += " MouseButtonDblClick";
          else if ( _event->type() == QEvent::MouseMove )
            message += " MouseMove";
          else
880
            message += tr("unknown event type");
881 882 883 884

          emit log(LOGINFO,message );
        }

Jan Möbius's avatar
Jan Möbius committed
885
        break;
886

Jan Möbius's avatar
Jan Möbius committed
887 888 889 890 891 892 893
      }
    }

  }

  PluginFunctions::setActiveExaminer( examinerId );

Jan Möbius's avatar
 
Jan Möbius committed
894 895 896 897 898 899 900 901
  emit PluginMouseEvent(_event );
}

//-----------------------------------------------------------------------------

void
Core::slotWheelEvent( QWheelEvent * _event, const std::string & _mode)
{
Jan Möbius's avatar
Jan Möbius committed
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
  const QObject* senderPointer = sender();
  unsigned int examinerId = 0;

  if ( senderPointer == 0 ) {
    std::cerr << "Error : slotWheelEvent directly called! This should only be called by an examiner" << std::endl;
  } else {
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
      if ( senderPointer == coreWidget_->examiner_widgets_[i] ) {
        examinerId = i;
        break;
      }
    }

  }

  PluginFunctions::setActiveExaminer( examinerId );

Jan Möbius's avatar
 
Jan Möbius committed
919 920 921 922 923 924
  emit PluginWheelEvent(_event , _mode );
}

//-----------------------------------------------------------------------------

void
Jan Möbius's avatar
Jan Möbius committed
925
Core::slotAddPickMode( const std::string& _mode ) {
Jan Möbius's avatar
 
Jan Möbius committed
926
  if ( OpenFlipper::Options::gui() )
927
    coreWidget_->addPickMode(_mode);
Jan Möbius's avatar
Jan Möbius committed
928

Jan Möbius's avatar
 
Jan Möbius committed
929 930 931 932 933
}

//-----------------------------------------------------------------------------

void
Jan Möbius's avatar
Jan Möbius committed
934
Core::slotAddHiddenPickMode( const std::string& _mode ) {
Jan Möbius's avatar
Jan Möbius committed
935

Jan Möbius's avatar
 
Jan Möbius committed
936
  if ( OpenFlipper::Options::gui() )
937
    coreWidget_->addPickMode(_mode,false,1000,false);
Jan Möbius's avatar
Jan Möbius committed
938

Jan Möbius's avatar
 
Jan Möbius committed
939 940 941 942 943 944
}

//-----------------------------------------------------------------------------

 /** Update the view in the examiner widget
  */
Jan Möbius's avatar
Jan Möbius committed
945 946
void Core::updateView()
{
Jan Möbius's avatar
Jan Möbius committed
947

Jan Möbius's avatar
Jan Möbius committed
948 949 950 951
  if (OpenFlipper::Options::doSlotDebugging()) {
    if (sender() != 0) {
      if (sender()->metaObject() != 0) {
        emit log(LOGINFO, tr("updateView() called by ") + QString(sender()->metaObject()->className()));
Jan Möbius's avatar
Jan Möbius committed
952 953 954 955
      }
    }
  }

Jan Möbius's avatar
Jan Möbius committed
956
  if (!OpenFlipper::Options::gui())
Dirk Wilden's avatar
Dirk Wilden committed
957
    return;
958

Jan Möbius's avatar
Jan Möbius committed
959 960 961
  if (OpenFlipperSettings().value("Core/Gui/glViewer/restrictFrameRate", false).toBool()) {

    int elapsed = redrawTime_->elapsed();
962

Jan Möbius's avatar
Jan Möbius committed
963
    if (elapsed < 1000 / OpenFlipperSettings().value("Core/Gui/glViewer/maxFrameRate", 35).toInt()) {
Jan Möbius's avatar
Jan Möbius committed
964
      // redraw time not reached ... waiting for timer event for next redraw
Jan Möbius's avatar
Jan Möbius committed
965 966 967 968
      if (redrawTimer_->isActive()) {
        if (OpenFlipper::Options::doSlotDebugging())
          emit log(LOGINFO,
              tr("Too early for redraw! Delaying request from ") + QString(sender()->metaObject()->className()));
Jan Möbius's avatar
Jan Möbius committed
969 970 971 972
        return;
      }

      // Start the timer
Jan Möbius's avatar
Jan Möbius committed
973
      redrawTimer_->start((1000 / OpenFlipperSettings().value("Core/Gui/glViewer/maxFrameRate", 35).toInt()) - elapsed);
Jan Möbius's avatar
Jan Möbius committed
974
      return;
Jan Möbius's avatar
Jan Möbius committed
975 976
    } else if (redrawTimer_->isActive())
      redrawTimer_->stop();
977 978 979

  }

Jan Möbius's avatar
Jan Möbius committed
980
  redrawTime_->restart();
981

982
  if (!OpenFlipper::Options::sceneGraphUpdatesBlocked() && !OpenFlipper::Options::redrawDisabled()) {
Jan Möbius's avatar
Jan Möbius committed
983

Jan Möbius's avatar
Jan Möbius committed
984
    for (unsigned int i = 0; i < OpenFlipper::Options::examinerWidgets(); ++i)
Jan Möbius's avatar
Jan Möbius committed
985
      coreWidget_->examiner_widgets_[i]->updateGL();
986 987 988

    // Inform plugins of the scene update
    emit pluginSceneDrawn();
Jan Möbius's avatar
 
Jan Möbius committed
989
  }
990 991


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