openFunctions.cc 28.5 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
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
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2010 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/>.                                       *
*                                                                            *
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





#include "Core.hh"

#include <ACG/QtWidgets/QtFileDialog.hh>

#include "OpenFlipper/common/GlobalOptions.hh"
52
#include <OpenFlipper/common/RecentFiles.hh>
Jan Möbius's avatar
 
Jan Möbius committed
53
54
55
56
57
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"

#include "OpenFlipper/widgets/loadWidget/loadWidget.hh"
#include "OpenFlipper/widgets/addEmptyWidget/addEmptyWidget.hh"

58
59
60
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>

61
62
#include <time.h>

63
void Core::resetScenegraph( bool _resetTrackBall  ) {
64
  if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() ) {
Jan Möbius's avatar
Jan Möbius committed
65
66

    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
67
      // update scene graph (get new bounding box and set projection right, including near and far plane)
68
      PluginFunctions::viewerProperties(i).lockUpdate();
69
      coreWidget_->examiner_widgets_[i]->sceneGraph(root_node_scenegraph_, _resetTrackBall );
70
      PluginFunctions::viewerProperties(i).unLockUpdate();
Jan Möbius's avatar
Jan Möbius committed
71
72
73
      coreWidget_->examiner_widgets_[i]->updateGL();
    }

Jan Möbius's avatar
 
Jan Möbius committed
74
  }
75

Jan Möbius's avatar
Jan Möbius committed
76
  // Update the draw Modes Menu
Dirk Wilden's avatar
Dirk Wilden committed
77
78
  if ( OpenFlipper::Options::gui() )
    coreWidget_->slotUpdateGlobalDrawMenu();
Jan Möbius's avatar
 
Jan Möbius committed
79
80
81
82
83
84
85
86
87
}

//========================================================================================
// ===            Open/Add-Empty Functions                    ============================
//========================================================================================


void Core::slotGetAllFilters ( QStringList& _list){

88
  /// \todo check why the supported Type is used here!
Jan Möbius's avatar
Jan Möbius committed
89
  // Iterate over all types
Jan Möbius's avatar
 
Jan Möbius committed
90
91
92
  for (int i=0; i < (int)supportedTypes_.size(); i++){
    QString f = supportedTypes_[i].plugin->getLoadFilters();
    f = f.section(")",0,0).section("(",1,1).trimmed();
93
    _list << (QString::number(supportedTypes_[i].plugin->supportedType().value()) + " " + f);
Jan Möbius's avatar
 
Jan Möbius committed
94
95
96
  }
}

97
void Core::commandLineOpen(const char* _filename, bool _asPolyMesh ){
98

Jan Möbius's avatar
Jan Möbius committed
99
  QString file(_filename);
100

101
  // Modify filename to contain full paths if they were given as relative paths
Jan Möbius's avatar
Jan Möbius committed
102
103
104
105
106
  if ( !file.startsWith("/") && !file.contains(":") ) {
    file = QDir::currentPath();
    file += OpenFlipper::Options::dirSeparator();
    file += _filename;
  }
107

Jan Möbius's avatar
Jan Möbius committed
108
  // Add to the open list
109
  commandLineFileNames_.push_back(std::pair< std::string , bool >(file.toStdString(), _asPolyMesh));
Jan Möbius's avatar
 
Jan Möbius committed
110
111
112
}

void Core::commandLineScript(const char* _filename ) {
113
114
115
116
117
118
119
120
121
122
123
124

  QString file(_filename);
  
  // Modify filename to contain full paths if they were given as relative paths
  if ( !file.startsWith("/") && !file.contains(":") ) {
    file = QDir::currentPath();
    file += OpenFlipper::Options::dirSeparator();
    file += _filename;
  }
  
  // Add to the open list
  commandLineScriptNames_.push_back(file.toStdString());
125
126
}

Jan Möbius's avatar
Jan Möbius committed
127
128
129
130
131
132
void Core::slotExecuteAfterStartup() {

  //check if we have scripting support:
  bool scriptingSupport = false;
  slotPluginExists("scripting",scriptingSupport);
  if ( ! scriptingSupport ) {
133
    emit log(LOGERR ,tr("No scripting support available, please check if we load a scripting plugin .. Skipping script execution on startup"));
Jan Möbius's avatar
Jan Möbius committed
134
135
  }

Jan Möbius's avatar
Jan Möbius committed
136
137
138
  // Collect all script files from the scripting subdirectory and execute them if possible.
  // You can use this directory to execute scipts that modify for example modify the ui at
  // every startup.
Jan Möbius's avatar
Jan Möbius committed
139
140
  if ( scriptingSupport ) {

Jan Möbius's avatar
Jan Möbius committed
141
    // Get the files in the directory
Jan Möbius's avatar
Jan Möbius committed
142
143
144
    QDir scriptDir = OpenFlipper::Options::scriptDir();
    QStringList scriptFiles = scriptDir.entryList(QDir::Files,QDir::Name);

Jan Möbius's avatar
Jan Möbius committed
145
    // Execute all files ending with ofs
Jan Möbius's avatar
Jan Möbius committed
146
    for ( int i = 0 ; i  < scriptFiles.size(); ++i )
147
      if ( scriptFiles[i].endsWith("ofs",Qt::CaseInsensitive) )
148
        emit executeFileScript(scriptDir.path() + "/" + scriptFiles[i]);
Jan Möbius's avatar
Jan Möbius committed
149
150
151

  }

Jan Möbius's avatar
Jan Möbius committed
152
  // Open all files given at the commandline
153
  for ( uint i = 0 ; i < commandLineFileNames_.size() ; ++i ) {
154
155

    // Skip scripts here as they will be handled by a different function
156
    QString tmp = QString::fromStdString(commandLineFileNames_[i].first);
157
    if ( tmp.endsWith("ofs",Qt::CaseInsensitive) ) {
158
159
160
161
      commandLineScriptNames_.push_back(commandLineFileNames_[i].first);
      continue;
    }

Jan Möbius's avatar
Jan Möbius committed
162
    // If the file was given with the polymesh option, open them as polymeshes.
163
    if (commandLineFileNames_[i].second)
164
165
166
167
      loadObject(DATA_POLY_MESH, QString::fromStdString(commandLineFileNames_[i].first));
    else {
      loadObject(QString::fromStdString(commandLineFileNames_[i].first));
    }
Jan Möbius's avatar
 
Jan Möbius committed
168
169
  }

Jan Möbius's avatar
Jan Möbius committed
170
  // If we have scripting support, execute the scripts given at the commandline.
Jan Möbius's avatar
Jan Möbius committed
171
  if ( scriptingSupport )
172
    for ( uint i = 0 ; i < commandLineScriptNames_.size() ; ++i ) {
173
      emit executeFileScript(QString::fromStdString(commandLineScriptNames_[i]));
174
    }
175

Jan Möbius's avatar
Jan Möbius committed
176
177
  // If we don't have a gui and we are not under remote control,
  // exit the application as there would be no way to execute further commands
Dirk Wilden's avatar
Dirk Wilden committed
178
179
  if ( !OpenFlipper::Options::gui() && !OpenFlipper::Options::remoteControl())
    exitApplication();
Jan Möbius's avatar
 
Jan Möbius committed
180
181
}

182

Jan Möbius's avatar
Jan Möbius committed
183
184
185
186
187
188
189
int Core::loadObject ( QString _filename ) {
  /** \todo Check if this function is ok. It should check all plugins for the given files and do not depend
            on Triangle meshes only! 
            Rewrite function to get the plugin only and then open the file. So iterate over all plugins and find the
            matching ones. open it with this plugin.
  */
  
190
  if (_filename.endsWith(".ini",Qt::CaseInsensitive)) {
191
192

    // Load all information from the given ini file
193
    openIniFile(_filename,true,true,true);
194

Jan Möbius's avatar
 
Jan Möbius committed
195
    if ( OpenFlipper::Options::gui() )
196
      coreWidget_->addRecent(_filename, DATA_UNKNOWN);
197

Jan Möbius's avatar
 
Jan Möbius committed
198
    return -2;
199
  } else if (_filename.endsWith(".ofs",Qt::CaseInsensitive)) {
Jan Möbius's avatar
Jan Möbius committed
200
     emit log(LOGINFO ,tr("Starting script execution of %1.").arg( _filename)) ;
Jan Möbius's avatar
 
Jan Möbius committed
201
     emit executeFileScript(_filename);
Dirk Wilden's avatar
Dirk Wilden committed
202
203
204
  } else {
    
    QFileInfo fi(_filename);
205

Dirk Wilden's avatar
Dirk Wilden committed
206
207
208
209
    for (int i=0; i < (int)supportedTypes_.size(); i++){

      QString filters = supportedTypes_[i].plugin->getLoadFilters();
      //check extension
Jan Möbius's avatar
Jan Möbius committed
210
      if ( ! filters.contains( "*." + fi.completeSuffix() , Qt::CaseInsensitive) ) {
211
212
213
214
215
        if (  ! filters.contains( "*." + fi.suffix() , Qt::CaseInsensitive) ) {
          continue;
        } else {
          emit log(LOGWARN,"Found supported datatype but only the suffix is matched not the complete suffix!"); 
        }
Jan Möbius's avatar
Jan Möbius committed
216
      }
Dirk Wilden's avatar
Dirk Wilden committed
217
218
219
220
221
222
223
224
225
226
227

      if ( OpenFlipper::Options::gui() ) {
        coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
        if ( !OpenFlipper::Options::loadingSettings() )
          coreWidget_->setStatus(ApplicationStatus::PROCESSING );
      }

      //load file
      int id = supportedTypes_[i].plugin->loadObject(_filename);

      if ( OpenFlipper::Options::gui() ) {
228
        if ( id != -1 ) {
Dirk Wilden's avatar
Dirk Wilden committed
229
          coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
230
231
232
233
234
235
236
237
238
239
          
          // Get the object to figure out the data type
          BaseObject* object;
          PluginFunctions::getObject(id,object);
          
          // Add to recent files with the given datatype
          if ( OpenFlipper::Options::gui() )
            coreWidget_->addRecent(_filename, object->dataType());
          
        } else
Dirk Wilden's avatar
Dirk Wilden committed
240
241
242
243
244
245
246
247
248
249
250
          coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );

        if ( !OpenFlipper::Options::loadingSettings() )
          coreWidget_->setStatus(ApplicationStatus::READY );
      }

      return id;
    }
  }

  emit log(LOGERR, tr("Unable to load object (type unknown). No suitable plugin found!") );
Jan Möbius's avatar
 
Jan Möbius committed
251
252
253
254
255
256

  return -1;
}

/// Function for loading a given file
int Core::loadObject( DataType _type, QString _filename) {
Jan Möbius's avatar
Jan Möbius committed
257
258
259
  /** \todo this function has to be checked. test for the plugin which can handle 
            the given file and then use it. 
  */
260
  
261
  if (_type == DATA_UNKNOWN)
Jan Möbius's avatar
 
Jan Möbius committed
262
263
    return loadObject(_filename);

Dirk Wilden's avatar
Dirk Wilden committed
264
265
  QFileInfo fi(_filename);
  
Jan Möbius's avatar
 
Jan Möbius committed
266
  for (int i=0; i < (int)supportedTypes_.size(); i++)
Dirk Wilden's avatar
Dirk Wilden committed
267
    if (supportedTypes_[i].type & _type || supportedTypes_[i].type == _type) {
Jan Möbius's avatar
 
Jan Möbius committed
268

Dirk Wilden's avatar
Dirk Wilden committed
269
270
      QString filters = supportedTypes_[i].plugin->getLoadFilters();
      //check extension
271
      if ( ! filters.contains( "*." + fi.suffix() ,Qt::CaseInsensitive ) )
Dirk Wilden's avatar
Dirk Wilden committed
272
273
274
        continue;
        
      
Jan Möbius's avatar
 
Jan Möbius committed
275
      if ( OpenFlipper::Options::gui() ) {
Jan Möbius's avatar
Jan Möbius committed
276
        coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
277
        if ( !OpenFlipper::Options::loadingSettings() )
Jan Möbius's avatar
 
Jan Möbius committed
278
279
280
          coreWidget_->setStatus(ApplicationStatus::PROCESSING );
      }

Dirk Wilden's avatar
Dirk Wilden committed
281
282
      int id = -1;

Jan Möbius's avatar
 
Jan Möbius committed
283
      //load file
Dirk Wilden's avatar
Dirk Wilden committed
284
285
286
287
      if ( checkSlot( supportedTypes_[i].object , "loadObject(QString,DataType)" ) )
        id = supportedTypes_[i].plugin->loadObject(_filename, _type);
      else
        id = supportedTypes_[i].plugin->loadObject(_filename);
Jan Möbius's avatar
 
Jan Möbius committed
288
289

      if ( OpenFlipper::Options::gui() ) {
290
        if ( id != -1 ) {
Jan Möbius's avatar
Jan Möbius committed
291
          coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
292
293
294
295
296
297
298
299
300
301
          
          // Get the object to figure out the data type
          BaseObject* object;
          PluginFunctions::getObject(id,object);
          
          // Add to recent files with the given datatype
          if ( OpenFlipper::Options::gui() )
            coreWidget_->addRecent(_filename, object->dataType());
          
        } else
Jan Möbius's avatar
Jan Möbius committed
302
          coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );
Jan Möbius's avatar
 
Jan Möbius committed
303

304
        if ( !OpenFlipper::Options::loadingSettings() )
Jan Möbius's avatar
 
Jan Möbius committed
305
306
307
308
309
          coreWidget_->setStatus(ApplicationStatus::READY );
      }

      return id;
    }
Dirk Wilden's avatar
Dirk Wilden committed
310
311
312
    
  emit log(LOGERR, tr("Unable to load object. No suitable plugin found!") );
    
Jan Möbius's avatar
 
Jan Möbius committed
313
314
315
  return -1; //no plugin found
}

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

Jan Möbius's avatar
 
Jan Möbius committed
317
int Core::addEmptyObject( DataType _type ) {
318
319
  // Iterate over all plugins. The first plugin supporting the addEmpty function for the
  // specified type will be used to create the new object.
320
321
322
323
324
325
326
327
328
329
330
  
  int retCode = -1;
  
  // Type plugins
  for (int i=0; i < (int)supportedDataTypes_.size(); i++)
    if ( supportedDataTypes_[i].type & _type )
      retCode = supportedDataTypes_[i].plugin->addEmpty();
  
  if(retCode != -1) return retCode;
    
  // File plugins
Jan Möbius's avatar
 
Jan Möbius committed
331
  for (int i=0; i < (int)supportedTypes_.size(); i++)
Jan Möbius's avatar
Jan Möbius committed
332
    if ( supportedTypes_[i].type & _type ) {
333
      emit log(LOGERR, tr("File Plugins are not allowed to create empty objects anymore! Use the addEmpty call instead!") );
334
      retCode = supportedTypes_[i].plugin->addEmpty();
Jan Möbius's avatar
Jan Möbius committed
335
    }
336
337
  
  return retCode; // -1 if no plugin found
Jan Möbius's avatar
 
Jan Möbius committed
338
339
340
341
342
343
344
345
}

//========================================================================================
// ===             Open/Add-Empty Slots                       ============================
//========================================================================================

/// Slot for adding an empty object of given DataType
void Core::slotAddEmptyObject( DataType _type , int& _id ) {
346
347
348
  
  _id = addEmptyObject( _type );
  
Jan Möbius's avatar
Jan Möbius committed
349
350
351
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
352
        emit log(LOGINFO,"slotAddEmptyObject( " + _type.name() + "," + QString::number(_id) +  tr(" ) called by ") +
Jan Möbius's avatar
Jan Möbius committed
353
354
355
        QString( sender()->metaObject()->className() ) );
      }
    } else {
356
      emit log(LOGINFO,"slotAddEmptyObject( " + _type.name() + ","  + QString::number(_id) +  tr(" ) called by Core") );
Jan Möbius's avatar
Jan Möbius committed
357
358
    }
  }
Jan Möbius's avatar
 
Jan Möbius committed
359
360
}

361
/// Slot creating a copy of an existing object
Jan Möbius's avatar
Jan Möbius committed
362
void Core::slotCopyObject( int _oldId , int& _newId ) {
363

Jan Möbius's avatar
Jan Möbius committed
364
  if ( _oldId == -1 ) {
Jan Möbius's avatar
Jan Möbius committed
365
    emit log(LOGERR,tr("Requested copy for illegal Object id: %1").arg(_oldId) );
Jan Möbius's avatar
Jan Möbius committed
366
367
368
369
370
371
372
373
    _newId = -1;
    return;
  }

  // get the node
  BaseObject* object = objectRoot_->childExists(_oldId);

  if ( !object ) {
Jan Möbius's avatar
Jan Möbius committed
374
    emit log(LOGERR,tr("Requested copy for unknown Object id: %1 ").arg(_oldId) );
Jan Möbius's avatar
Jan Möbius committed
375
376
377
378
379
380
381
382
    _newId = -1;
    return ;
  }

  // Copy the item
  BaseObject* copy = object->copy();

  if ( copy == 0 ) {
383
    emit log(LOGERR,tr("Unable to create a copy of the object."));
Jan Möbius's avatar
Jan Möbius committed
384
385
386
387
388
389
    return;
  }

  // Integrate into object tree
  copy->setParent( object->parent() );

390
  // return the new id
Jan Möbius's avatar
Jan Möbius committed
391
  _newId = copy->id();
392

393
394
395
396
397
398
  // tell plugins that a new object has been created
  slotEmptyObjectAdded(_newId);

  // tell plugins that the object has been updated
  slotObjectUpdated(_newId);

399
400
}

Dirk Wilden's avatar
Dirk Wilden committed
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/// Function for loading a given file
void Core::slotLoad(QString _filename, int _pluginID) {

  if ( OpenFlipper::Options::gui() ) {
    coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
    if ( !OpenFlipper::Options::loadingSettings() )
      coreWidget_->setStatus(ApplicationStatus::PROCESSING );
  }

  //load file
  int id = supportedTypes_[_pluginID].plugin->loadObject(_filename);

  if ( OpenFlipper::Options::gui() ) {
    if ( id != -1 )
      coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
    else
      coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );

    if ( !OpenFlipper::Options::loadingSettings() )
      coreWidget_->setStatus(ApplicationStatus::READY );
  }
  
423
424
425
426
427
  // Initialize as unknown type
  DataType type = DATA_UNKNOWN;

  // An object has been added. Get it and do some processing!
  if ( id > 0 ) {
428

429
430
    BaseObjectData* object;
    PluginFunctions::getObject(id,object);
Dirk Wilden's avatar
Dirk Wilden committed
431
    
432
    if ( !object ) {
Dirk Wilden's avatar
Dirk Wilden committed
433
434
435
436
437
438
439
440
441
442
443

      BaseObject* baseObj = 0;
      GroupObject* group = 0;
      
      PluginFunctions::getObject(id,baseObj);
      
      if (baseObj){

        group = dynamic_cast< GroupObject* > (baseObj);

        if (group)
444
          type = DATA_GROUP;
Dirk Wilden's avatar
Dirk Wilden committed
445
446
447
448
449
450
      }
      
      if ( group == 0 ){
        emit log(LOGERR,tr("Object id returned but no object with this id has been found! Error in one of the file plugins!"));
        return;
      }
451
452
453
    }
    
    // Get the objects type
Dirk Wilden's avatar
Dirk Wilden committed
454
455
    if (object)
      type = object->dataType();
Dirk Wilden's avatar
Dirk Wilden committed
456
  }
457
458
  
  // If the id was greater than zero, add the file to the recent files.
Dirk Wilden's avatar
Dirk Wilden committed
459
460
461
462
463
  if ( id >= 0 )
    if ( OpenFlipper::Options::gui() )
      coreWidget_->addRecent(_filename, type);
}

Jan Möbius's avatar
 
Jan Möbius committed
464
465
466
/// Slot for loading a given file
void Core::slotLoad(QString _filename, DataType _type, int& _id) {
  _id = loadObject(_type,_filename);
467

Jan Möbius's avatar
 
Jan Möbius committed
468
469
470
  if ( _id < 0 )
    _id = -1;
  else
471
    if ( OpenFlipper::Options::gui() )
Jan Möbius's avatar
 
Jan Möbius committed
472
473
474
475
      coreWidget_->addRecent(_filename,_type);
}

/// Slot gets called after a file-plugin has opened an object
476
477
478
479
void Core::slotObjectOpened ( int _id ) {
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
480
        emit log(LOGINFO,tr("slotObjectOpened( ") + QString::number(_id) + tr(" ) called by ") +
481
482
483
                  QString( sender()->metaObject()->className() ) );
      }
    } else {
484
      emit log(LOGINFO,tr("slotObjectOpened( ") + QString::number(_id) + tr(" ) called by Core") );
485
486
    }
  }
487
488

  // get the opened object
489
490
  BaseObjectData* object;
  PluginFunctions::getObject(_id,object);
491

Jan Möbius's avatar
Jan Möbius committed
492
  // ================================================================================
493
  // Set defaults for DrawMode, ViewingDirection and Projection if this is the first opened object
Jan Möbius's avatar
Jan Möbius committed
494
495
496
  // If a plugin changes the drawmode later, this setting will be overridden!
  // ================================================================================
  if ( PluginFunctions::objectCount() == 1 && OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() )
497
498
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ){
      PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) );
499

500
      if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
Dirk Wilden's avatar
Dirk Wilden committed
501
        PluginFunctions::orthographicProjection(i);
502
      else
Dirk Wilden's avatar
Dirk Wilden committed
503
        PluginFunctions::perspectiveProjection(i);
504
505
506

      PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
    }
Jan Möbius's avatar
Jan Möbius committed
507
508
509

  // ================================================================================
  // Recompute bounding box and scenegraph info
510
  // Reset scene center here to include new object
Jan Möbius's avatar
Jan Möbius committed
511
  // ================================================================================
512
  resetScenegraph(true);
Jan Möbius's avatar
 
Jan Möbius committed
513

Jan Möbius's avatar
Jan Möbius committed
514
515
516
  // ================================================================================
  // Tell plugins, that a file has been opened
  // ================================================================================
517
  emit openedFile( _id );
518
519
520
521
522
  
  // ================================================================================
  // Print Info to logger
  // ================================================================================
  emit log( LOGINFO ,object->getObjectinfo() );
Jan Möbius's avatar
 
Jan Möbius committed
523

Jan Möbius's avatar
Jan Möbius committed
524
525
526
  // ================================================================================
  // Tell plugins, that the Object is updated and the active object has changed
  // ================================================================================
Jan Möbius's avatar
Jan Möbius committed
527
528
  emit signalObjectUpdated(_id );
  emit signalObjectUpdated(_id, UPDATE_ALL);
Jan Möbius's avatar
 
Jan Möbius committed
529

Jan Möbius's avatar
Jan Möbius committed
530
531
532
  // ================================================================================
  // Create initial backup
  // ================================================================================
Jan Möbius's avatar
Jan Möbius committed
533
534
  int backupId = 0;
  slotBackup(_id,"Original Object",backupId);
Jan Möbius's avatar
 
Jan Möbius committed
535

536
537
538
  // ================================================================================
  // Add the file to the recent files menu
  // ================================================================================
539
540
541
  QString filename = object->path() + OpenFlipper::Options::dirSeparator() + object->name();
  BaseObject* object2;
  PluginFunctions::getObject(_id,object2);
Jan Möbius's avatar
 
Jan Möbius committed
542

Jan Möbius's avatar
Jan Möbius committed
543
544
545
  // ================================================================================
  // if this is the first object opend, reset the global view
  // ================================================================================
546
  if ( PluginFunctions::objectCount() == 1 && OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() )
547
548
549
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      coreWidget_->examiner_widgets_[i]->viewAll();
    }
550

Jan Möbius's avatar
 
Jan Möbius committed
551
  // objectRoot_->dumpTree();
552
}
Jan Möbius's avatar
 
Jan Möbius committed
553
554

 /// Slot gets called after a file-plugin has opened an object
555
void Core::slotEmptyObjectAdded ( int _id ) {
556

557
558
559
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
560
        emit log(LOGINFO,tr("slotEmptyObjectAdded( ") + QString::number(_id) + tr(" ) called by ") +
561
562
563
                  QString( sender()->metaObject()->className() ) );
      }
    } else {
564
      emit log(LOGINFO,tr("slotEmptyObjectAdded( ") + QString::number(_id) + tr(" ) called by Core") );
565
566
567
    }
  }

568
569
570
571
  // get the opened object
  BaseObjectData* object;
  PluginFunctions::getObject(_id,object);

572
  
573
  emit emptyObjectAdded( _id );
574

Jan Möbius's avatar
 
Jan Möbius committed
575
  // Tell the Plugins that the Object List and the active object have changed
576
  emit signalObjectUpdated(_id);
Jan Möbius's avatar
Jan Möbius committed
577
  emit signalObjectUpdated(_id,UPDATE_ALL);
Jan Möbius's avatar
 
Jan Möbius committed
578

579
  ///@todo : set a default path for new objects
Jan Möbius's avatar
 
Jan Möbius committed
580
581
582
//    QString filename = object->path() + OpenFlipper::Options::dirSeparator() + object->name();

//    addRecent(filename);
583
}
Jan Möbius's avatar
 
Jan Möbius committed
584
585
586
587
588
589
590

//========================================================================================
// ===             Menu Slots                                 ============================
//========================================================================================

/// Opens AddEmpty-Object widget
void Core::slotAddEmptyObjectMenu() {
591
592
593
594
595
596
597
598
599
600
601
602
603
  std::vector< DataType > types;
  QStringList             typeNames;
  
  DataType currentType = 2;
  
  // Iterate over all Types known to the core
  // Start at 2:
  // 0 type is defined as DATA_UNKNOWN
  // 1 type is defined as DATA_GROUP
  // Therefore we have two types less then reported
  // 
  for ( uint i = 0 ; i < typeCount() - 2  ; ++i) {
    
604
    // Iterate over all supported types (created from plugins on load)
605
606
    // Check if a plugin supports addEmpty for the current type.
    // Only if the type is supported, add it to the addEmpty Dialog
607
608
609
    
    // typePlugin
    for ( uint j = 0 ; j < supportedDataTypes_.size(); j++) {
610
      
611
612
      // Check if a plugin supports the current type
      if ( supportedDataTypes_[j].type & currentType ) {
613
614
615
616
617
        types.push_back(currentType);
        typeNames.push_back( typeName( currentType ) );
        
        // Stop here as we need only one plugin supporting addEmpty for a given type
        break;
Jan Möbius's avatar
   
Jan Möbius committed
618
      }
619
620
    }
    
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
    // filePlugin
    for ( uint j = 0 ; j < supportedTypes_.size(); j++) {
      
      // Check if a plugin supports the current Type
      if ( supportedTypes_[j].type & currentType ) {
	
	// Avoid duplicates
	bool duplicate = false;
	for(std::vector< DataType >::iterator it = types.begin(); it != types.end(); ++it) {
	  if(*it == currentType) {
	    duplicate = true;
	    break;
	  }
	}
	  
	if(!duplicate) {
	  types.push_back(currentType);
	  typeNames.push_back( typeName( currentType ) );
        
	  // Stop here as we need only one plugin supporting addEmpty for a given type
	  break;
	}
      }
    }
    
646
    // Advance to next type ( Indices are bits so multiply by to to get next bit)
647
    currentType++;
648
649
650
651
652
653
654
  }
  
  static addEmptyWidget* widget = 0;
  
  if (supportedTypes_.size() != 0) {
    
    if ( !widget ){
Jan Möbius's avatar
 
Jan Möbius committed
655
      widget = new addEmptyWidget(types,typeNames);
656
      widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
Jan Möbius's avatar
 
Jan Möbius committed
657
658
      connect(widget,SIGNAL(chosen(DataType, int&)),this,SLOT(slotAddEmptyObject(DataType, int&)));
    }
659
    
Jan Möbius's avatar
 
Jan Möbius committed
660
    widget->show();
661
662
663
664
    
  } else
    emit log(LOGERR,tr("Could not show 'add Empty' dialog. Missing file-plugins ?"));
  
Jan Möbius's avatar
 
Jan Möbius committed
665
666
}

667
668
669
670
//========================================================================================
// ===             Public Slots                                 ============================
//========================================================================================

Jan Möbius's avatar
 
Jan Möbius committed
671
/// Open Load-Object Widget
672
673
674
675
676
void Core::loadObject() {

  if ( OpenFlipper::Options::gui() ){

    if (supportedTypes_.size() != 0){
677
      LoadWidget* widget = new LoadWidget(supportedTypes_);
Dirk Wilden's avatar
Dirk Wilden committed
678
679
      connect(widget,SIGNAL(load(QString, int)),this,SLOT(slotLoad(QString, int)));
      connect(widget,SIGNAL(save(int, QString, int)),this,SLOT(saveObject(int, QString, int)));
Jan Möbius's avatar
Jan Möbius committed
680

681
682
      widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );

683
      widget->showLoad();
684
685
686
687

      widget->disconnect();
      delete widget;

688
    }else
689
      emit log(LOGERR,tr("Could not show 'load objects' dialog. Missing file-plugins."));
Jan Möbius's avatar
 
Jan Möbius committed
690

691
  }
Jan Möbius's avatar
 
Jan Möbius committed
692
693
}

694
695
696
697
698
699
/// Load settings from file
void Core::loadSettings(){

  if ( OpenFlipper::Options::gui() ){

    QString complete_name;
Jan Möbius's avatar
Jan Möbius committed
700

701
702
703

    QFileDialog fileDialog( coreWidget_,
                            tr("Load Settings"),
704
                            OpenFlipperSettings().value("Core/CurrentDir").toString(),
705
                            tr("INI files (*.ini)") );
706

707
    fileDialog.setOption (QFileDialog::DontUseNativeDialog, true);
708
709
710
711
712
713
714
    fileDialog.setAcceptMode ( QFileDialog::AcceptOpen );
    fileDialog.setFileMode ( QFileDialog::AnyFile );

    QGridLayout *layout = (QGridLayout*)fileDialog.layout();

    QGroupBox* optionsBox = new QGroupBox( &fileDialog ) ;
    optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
715
    optionsBox->setTitle(tr("Options"));
716
717
718
    layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );

    QCheckBox *loadProgramSettings = new QCheckBox(optionsBox);
719
720
    loadProgramSettings->setText(tr("Load program settings"));
    loadProgramSettings->setToolTip(tr("Load all current program settings from the file ( This will include view settings, colors,...) "));
721
722
723
    loadProgramSettings->setCheckState( Qt::Unchecked );

    QCheckBox *loadPluginSettings = new QCheckBox(optionsBox);
724
725
    loadPluginSettings->setText(tr("Load per Plugin Settings"));
    loadPluginSettings->setToolTip(tr("Plugins should load their current global settings from the file"));
726
727
728
    loadPluginSettings->setCheckState( Qt::Checked );

    QCheckBox *loadObjectInfo = new QCheckBox(optionsBox);
729
730
    loadObjectInfo->setText(tr("Load all objects defined in the file"));
    loadObjectInfo->setToolTip(tr("Load all objects which are defined in the file"));
731
732
733
734
735
736
737
738
    loadObjectInfo->setCheckState( Qt::Checked );

    QBoxLayout* frameLayout = new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
    frameLayout->addWidget( loadProgramSettings , 0 , 0);
    frameLayout->addWidget( loadPluginSettings  , 1 , 0);
    frameLayout->addWidget( loadObjectInfo      , 2 , 0);
    frameLayout->addStretch();

Jan Möbius's avatar
Jan Möbius committed
739
740
    fileDialog.resize(550 ,500);

741
742
743
744
745
746
747
748
749
750
751
752
    // ========================================================================================
    // show the saveSettings-Dialog and get the target file
    // ========================================================================================
    QStringList fileNames;
    if (fileDialog.exec()) {
      fileNames = fileDialog.selectedFiles();
    } else {
      return;
    }

    if ( fileNames.size() > 1 ) {
      std::cerr << "Too many save filenames selected" << std::endl;
753
      return;
754
755
756
757
    }

    complete_name = fileNames[0];

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

759
    QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
760
    OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
Jan Möbius's avatar
Jan Möbius committed
761

762
    if ( complete_name.endsWith("ini",Qt::CaseInsensitive) ) {
763
764
765
766
      openIniFile( complete_name,
                   loadProgramSettings->isChecked(),
                   loadPluginSettings->isChecked(),
                   loadObjectInfo->isChecked());
767
768
      if ( loadProgramSettings->isChecked() )
        applyOptions();
769
770
    } 
    
771
    coreWidget_->addRecent(complete_name, DATA_UNKNOWN);
772
773
  }
}
Jan Möbius's avatar
 
Jan Möbius committed
774

775
776
/// Load settings from file
void Core::loadSettings(QString _filename){
Jan Möbius's avatar
Jan Möbius committed
777

778
  if ( !QFile(_filename).exists() )
Jan Möbius's avatar
 
Jan Möbius committed
779
780
    return;

781
  QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
782
  OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
Jan Möbius's avatar
 
Jan Möbius committed
783

784
  if ( _filename.endsWith("ini",Qt::CaseInsensitive) ) {
785
    // Loaded function for recent files. Load everything.
786
    openIniFile(_filename,true,true,true);
Jan Möbius's avatar
 
Jan Möbius committed
787
    applyOptions();
788
  } else if ( _filename.endsWith("obj",Qt::CaseInsensitive) ) {
Dirk Wilden's avatar
Dirk Wilden committed
789
    loadObject(_filename);
Jan Möbius's avatar
 
Jan Möbius committed
790
791
792
793
    applyOptions();
  }

}