openFunctions.cc 23.2 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





#include "Core.hh"

#include <ACG/QtWidgets/QtFileDialog.hh>

#include "OpenFlipper/common/GlobalOptions.hh"
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"

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

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

60
61
#include <time.h>

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

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

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

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

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


void Core::slotGetAllFilters ( QStringList& _list){

  for (int i=0; i < (int)supportedTypes_.size(); i++){
    QString f = supportedTypes_[i].plugin->getLoadFilters();
    f = f.section(")",0,0).section("(",1,1).trimmed();
    _list << (QString::number(supportedTypes_[i].plugin->supportedType()) + " " + f);
  }
}

void Core::commandLineOpen(const char* _filename, bool asPolyMesh ){
95
96
97
98
99
100
101
102
103
104
105

	QString file(_filename);

	if ( !file.startsWith("/") && !file.contains(":") ) {

		file = QDir::currentPath();
		file += OpenFlipper::Options::dirSeparator();
		file += _filename;
	}

	commandLineFileNames_.push_back(std::pair< std::string , bool >(file.toStdString(), asPolyMesh));
Jan Möbius's avatar
 
Jan Möbius committed
106
107
108
}

void Core::commandLineScript(const char* _filename ) {
109
110
111
  commandLineScriptNames_.push_back(_filename);
}

Jan Möbius's avatar
Jan Möbius committed
112
113
114
115
116
117
void Core::slotExecuteAfterStartup() {

  //check if we have scripting support:
  bool scriptingSupport = false;
  slotPluginExists("scripting",scriptingSupport);
  if ( ! scriptingSupport ) {
118
    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
119
120
121
122
123
124
125
126
127
  }

  // Collect all script files from the scripting subdirectory and execute them if possible
  if ( scriptingSupport ) {

    QDir scriptDir = OpenFlipper::Options::scriptDir();
    QStringList scriptFiles = scriptDir.entryList(QDir::Files,QDir::Name);

    for ( int i = 0 ; i  < scriptFiles.size(); ++i )
Jan Möbius's avatar
Jan Möbius committed
128
129
      if ( scriptFiles[i].endsWith("ofs") )
        emit executeFileScript(scriptDir.path() + QDir::separator() + scriptFiles[i]);
Jan Möbius's avatar
Jan Möbius committed
130
131
132

  }

133
  for ( uint i = 0 ; i < commandLineFileNames_.size() ; ++i ) {
134
135

    // Skip scripts here as they will be handled by a different function
136
    QString tmp = QString::fromStdString(commandLineFileNames_[i].first);
137
138
139
140
141
    if ( tmp.endsWith("ofs") ) {
      commandLineScriptNames_.push_back(commandLineFileNames_[i].first);
      continue;
    }

142
    if (commandLineFileNames_[i].second)
143
144
145
146
      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
147
148
  }

Jan Möbius's avatar
Jan Möbius committed
149
  if ( scriptingSupport )
150
151
    for ( uint i = 0 ; i < commandLineScriptNames_.size() ; ++i ) {
      // Add the full path to the script to set scripting dir right
152
      QString tmp = QString::fromStdString(commandLineScriptNames_[i]);
153
154
155
      tmp = QDir::currentPath() + QDir::separator() + tmp;
      emit executeFileScript(tmp);
    }
156

Dirk Wilden's avatar
Dirk Wilden committed
157
158
  if ( !OpenFlipper::Options::gui() && !OpenFlipper::Options::remoteControl())
    exitApplication();
Jan Möbius's avatar
 
Jan Möbius committed
159
160
161
162
}

/// Load object by guessing DataType depending on the files extension
int Core::loadObject ( QString _filename ) {
163

Jan Möbius's avatar
 
Jan Möbius committed
164
  if (_filename.endsWith(".ini")) {
165
166

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

Jan Möbius's avatar
 
Jan Möbius committed
169
170
    if ( OpenFlipper::Options::gui() )
      coreWidget_->addRecent(_filename, DATA_NONE);
171

Jan Möbius's avatar
 
Jan Möbius committed
172
173
174
    return -2;
  } else
  if (_filename.endsWith(".ofs")) {
Jan Möbius's avatar
Jan Möbius committed
175
     emit log(LOGINFO ,tr("Starting script execution of %1.").arg( _filename)) ;
Jan Möbius's avatar
 
Jan Möbius committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
     emit executeFileScript(_filename);
  } else
    return loadObject( DATA_TRIANGLE_MESH, _filename);

  return -1;
}

/// Function for loading a given file
int Core::loadObject( DataType _type, QString _filename) {

  if (_type == DATA_NONE)
    return loadObject(_filename);

  for (int i=0; i < (int)supportedTypes_.size(); i++)
    if (supportedTypes_[i].type == _type) {


      if ( OpenFlipper::Options::gui() ) {
Jan Möbius's avatar
Jan Möbius committed
194
        coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
195
        if ( !OpenFlipper::Options::loadingSettings() )
Jan Möbius's avatar
 
Jan Möbius committed
196
197
198
199
200
201
202
203
          coreWidget_->setStatus(ApplicationStatus::PROCESSING );
      }

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

      if ( OpenFlipper::Options::gui() ) {
        if ( id != -1 )
Jan Möbius's avatar
Jan Möbius committed
204
          coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
Jan Möbius's avatar
 
Jan Möbius committed
205
        else
Jan Möbius's avatar
Jan Möbius committed
206
          coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );
Jan Möbius's avatar
 
Jan Möbius committed
207

208
        if ( !OpenFlipper::Options::loadingSettings() )
Jan Möbius's avatar
 
Jan Möbius committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
          coreWidget_->setStatus(ApplicationStatus::READY );
      }

      return id;
    }
  return -1; //no plugin found
}

/// Function for adding an empty object of given DataType
int Core::addEmptyObject( DataType _type ) {
  for (int i=0; i < (int)supportedTypes_.size(); i++)
    if (supportedTypes_[i].type == _type)
      return supportedTypes_[i].plugin->addEmpty();
  return -1; //no plugin found
}

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

/// Slot for adding an empty object of given DataType
void Core::slotAddEmptyObject( DataType _type , int& _id ) {
  _id = addEmptyObject( _type );
}

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

Jan Möbius's avatar
Jan Möbius committed
237
  if ( _oldId == -1 ) {
Jan Möbius's avatar
Jan Möbius committed
238
    emit log(LOGERR,tr("Requested copy for illegal Object id: %1").arg(_oldId) );
Jan Möbius's avatar
Jan Möbius committed
239
240
241
242
243
244
245
246
    _newId = -1;
    return;
  }

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

  if ( !object ) {
Jan Möbius's avatar
Jan Möbius committed
247
    emit log(LOGERR,tr("Requested copy for unknown Object id: %1 ").arg(_oldId) );
Jan Möbius's avatar
Jan Möbius committed
248
249
250
251
252
253
254
255
    _newId = -1;
    return ;
  }

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

  if ( copy == 0 ) {
256
    emit log(LOGERR,tr("Unable to create a copy of the object."));
Jan Möbius's avatar
Jan Möbius committed
257
258
259
260
261
262
263
264
265
266
    return;
  }

  // Integrate into object tree
  copy->setParent( object->parent() );
  if ( object->parent() )
    object->parent()->appendChild(copy);
  else
    std::cerr << "Unable to add copy to object list" << std::endl;

267
  // return the new id
Jan Möbius's avatar
Jan Möbius committed
268
  _newId = copy->id();
269

270
271
272
273
274
275
  // tell plugins that a new object has been created
  slotEmptyObjectAdded(_newId);

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

276
277
}

Jan Möbius's avatar
 
Jan Möbius committed
278
279
280
/// Slot for loading a given file
void Core::slotLoad(QString _filename, DataType _type, int& _id) {
  _id = loadObject(_type,_filename);
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
  
  // Check if it is a polymesh
  if ( _type == DATA_POLY_MESH ) {
    
    PolyMeshObject* poly = 0;
    PluginFunctions::getObject(_id,poly);
    
    if ( poly != 0 ) {
        PolyMesh& mesh = *poly->mesh();
        
        bool isTriangleMesh = true;
        
        for ( PolyMesh::FaceIter f_it = mesh.faces_begin(); f_it != mesh.faces_end() ; ++f_it) {
          
          // Count number of vertices for the current face
          uint count = 0;
          for ( PolyMesh::FaceVertexIter fv_it( mesh,f_it); fv_it; ++fv_it ) 
            ++count;
          
          // Check if it is a triangle. If not, this is really a poly mesh
          if ( count != 3 ) {
            isTriangleMesh = false;
            break;
          }
          
        }
        
        // Mesh loaded as polymesh is actually a triangle mesh. Ask the user to reload as triangle mesh or keep it as poly mesh.
        if ( isTriangleMesh ) {
          QMessageBox::StandardButton result = QMessageBox::question ( 0, 
                                                                      tr("TriMesh loaded as PolyMesh"), 
                                                                      tr("You opened the mesh as a poly mesh but actually its a triangle mesh. \nShould it be opened as a triangle mesh?"), 
                                                                      (QMessageBox::Yes | QMessageBox::No ), 
                                                                      QMessageBox::Yes );
          // User decided to reload as triangle mesh                                                                    
          if ( result == QMessageBox::Yes ) {
            slotDeleteObject(_id);
            _id = loadObject(DATA_TRIANGLE_MESH ,_filename);
            _type = DATA_TRIANGLE_MESH;
          }
        }
        
    }
  }
Jan Möbius's avatar
 
Jan Möbius committed
325
326
327
  if ( _id < 0 )
    _id = -1;
  else
328
    if ( OpenFlipper::Options::gui() )
Jan Möbius's avatar
 
Jan Möbius committed
329
330
331
332
      coreWidget_->addRecent(_filename,_type);
}

/// Slot gets called after a file-plugin has opened an object
333
334
335
336
void Core::slotObjectOpened ( int _id ) {
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
337
        emit log(LOGINFO,tr("slotObjectOpened( ") + QString::number(_id) + tr(" ) called by ") +
338
339
340
                  QString( sender()->metaObject()->className() ) );
      }
    } else {
341
      emit log(LOGINFO,tr("slotObjectOpened( ") + QString::number(_id) + tr(" ) called by Core") );
342
343
    }
  }
344
345

  // get the opened object
346
347
  BaseObjectData* object;
  PluginFunctions::getObject(_id,object);
348

349
  QColor color;
350

351
  if ( OpenFlipper::Options::randomBaseColor() ){
352
353
354
355
356
      //init random seed
      srand ( time(NULL) );

      QColor bckgrnd = OpenFlipper::Options::defaultBackgroundColor();
      int diff;
357

358
359
      do{
        color.setRgb(rand()%255, rand()%255, rand()%255);
360

361
362
363
        diff = (bckgrnd.red()   - color.red())  *(bckgrnd.red()   - color.red())
              +(bckgrnd.green() - color.green())*(bckgrnd.green() - color.green())
              +(bckgrnd.blue()  - color.blue()) *(bckgrnd.blue()  - color.blue());
364
      }while (diff < 70000);
365
366
  }
  else{
367
      color = OpenFlipper::Options::defaultBaseColor();
368
  }
369

370
371
372
373
374
  ACG::Vec4f colorV;
  colorV[0] = color.redF();
  colorV[1] = color.greenF();
  colorV[2] = color.blueF();
  colorV[3] = color.alphaF();
375

376
  object->setBaseColor( colorV );
Jan Möbius's avatar
 
Jan Möbius committed
377

Jan Möbius's avatar
Jan Möbius committed
378
  // ================================================================================
379
  // Set defaults for DrawMode, ViewingDirection and Projection if this is the first opened object
Jan Möbius's avatar
Jan Möbius committed
380
381
382
  // If a plugin changes the drawmode later, this setting will be overridden!
  // ================================================================================
  if ( PluginFunctions::objectCount() == 1 && OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() )
383
384
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ){
      PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) );
385

386
387
388
389
390
391
392
      if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
	PluginFunctions::orthographicProjection(i);
      else
	PluginFunctions::perspectiveProjection(i);

      PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
    }
Jan Möbius's avatar
Jan Möbius committed
393
394
395

  // ================================================================================
  // Recompute bounding box and scenegraph info
396
  // Reset scene center here to include new object
Jan Möbius's avatar
Jan Möbius committed
397
  // ================================================================================
398
  resetScenegraph(true);
Jan Möbius's avatar
 
Jan Möbius committed
399

Jan Möbius's avatar
Jan Möbius committed
400
401
402
  // ================================================================================
  // Tell plugins, that a file has been opened
  // ================================================================================
403
  emit openedFile( _id );
Jan Möbius's avatar
 
Jan Möbius committed
404

Jan Möbius's avatar
Jan Möbius committed
405
406
407
  // ================================================================================
  // Tell plugins, that the Object is updated and the active object has changed
  // ================================================================================
408
409
  emit signalObjectUpdated(_id);
  emit objectSelectionChanged( _id );
Jan Möbius's avatar
 
Jan Möbius committed
410

Jan Möbius's avatar
Jan Möbius committed
411
412
413
  // ================================================================================
  // Create initial backup
  // ================================================================================
414
  backupRequest(_id,"Original Object");
Jan Möbius's avatar
 
Jan Möbius committed
415

416
417
418
  // ================================================================================
  // Add the file to the recent files menu
  // ================================================================================
419
420
421
422
  QString filename = object->path() + OpenFlipper::Options::dirSeparator() + object->name();
  BaseObject* object2;
  PluginFunctions::getObject(_id,object2);
  if ( OpenFlipper::Options::gui() )
Jan Möbius's avatar
 
Jan Möbius committed
423
424
    coreWidget_->addRecent( filename, object2->dataType() );

Jan Möbius's avatar
Jan Möbius committed
425
426
427
  // ================================================================================
  // if this is the first object opend, reset the global view
  // ================================================================================
428
  if ( PluginFunctions::objectCount() == 1 && OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() )
429
430
431
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      coreWidget_->examiner_widgets_[i]->viewAll();
    }
432

Jan Möbius's avatar
 
Jan Möbius committed
433
  // objectRoot_->dumpTree();
434
}
Jan Möbius's avatar
 
Jan Möbius committed
435
436

 /// Slot gets called after a file-plugin has opened an object
437
438
439
440
void Core::slotEmptyObjectAdded ( int _id ) {
  if ( OpenFlipper::Options::doSlotDebugging() ) {
    if ( sender() != 0 ) {
      if ( sender()->metaObject() != 0 ) {
441
        emit log(LOGINFO,tr("slotEmptyObjectAdded( ") + QString::number(_id) + tr(" ) called by ") +
442
443
444
                  QString( sender()->metaObject()->className() ) );
      }
    } else {
445
      emit log(LOGINFO,tr("slotEmptyObjectAdded( ") + QString::number(_id) + tr(" ) called by Core") );
446
447
448
    }
  }

449
450
451
452
453
  // get the opened object
  BaseObjectData* object;
  PluginFunctions::getObject(_id,object);

  emit emptyObjectAdded( _id );
454

Jan Möbius's avatar
 
Jan Möbius committed
455
  // Tell the Plugins that the Object List and the active object have changed
456
457
  emit signalObjectUpdated(_id);
  emit objectSelectionChanged(_id);
Jan Möbius's avatar
 
Jan Möbius committed
458

459
  backupRequest(_id,"Original Object");
Jan Möbius's avatar
 
Jan Möbius committed
460

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

//    addRecent(filename);
465
}
Jan Möbius's avatar
 
Jan Möbius committed
466
467
468
469
470
471
472
473
474
475
476
477

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

/// Opens AddEmpty-Object widget
void Core::slotAddEmptyObjectMenu() {
  if (supportedTypes_.size() != 0){
    static addEmptyWidget* widget = 0;
    if ( !widget ){
      std::vector< DataType > types;
      QStringList typeNames;
Jan Möbius's avatar
   
Jan Möbius committed
478
479
480
481
      for (int i=0; i < (int)supportedTypes_.size(); i++) {
        types.push_back(supportedTypes_[i].type);
        typeNames.push_back(supportedTypes_[i].plugin->typeName());
      }
Jan Möbius's avatar
 
Jan Möbius committed
482
      widget = new addEmptyWidget(types,typeNames);
483
      widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
Jan Möbius's avatar
 
Jan Möbius committed
484
485
486
487
      connect(widget,SIGNAL(chosen(DataType, int&)),this,SLOT(slotAddEmptyObject(DataType, int&)));
    }
    widget->show();
  }else
488
    emit log(LOGERR,tr("Could not show 'add Empty' dialog. Missing file-plugins."));
Jan Möbius's avatar
 
Jan Möbius committed
489
490
}

491
492
493
494
//========================================================================================
// ===             Public Slots                                 ============================
//========================================================================================

Jan Möbius's avatar
 
Jan Möbius committed
495
/// Open Load-Object Widget
496
497
498
499
500
void Core::loadObject() {

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

    if (supportedTypes_.size() != 0){
501
502
503
      LoadWidget* widget = new LoadWidget(supportedTypes_);
      connect(widget,SIGNAL(load(QString, DataType, int&)),this,SLOT(slotLoad(QString, DataType, int&)));
      connect(widget,SIGNAL(save(int, QString)),this,SLOT(saveObject(int, QString)));
Jan Möbius's avatar
Jan Möbius committed
504

505
506
      widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );

507
      widget->showLoad();
508
509
510
511

      widget->disconnect();
      delete widget;

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

515
  }
Jan Möbius's avatar
 
Jan Möbius committed
516
517
}

518
519
520
521
522
523
/// Load settings from file
void Core::loadSettings(){

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

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

525
526
527
528
529
530

    QFileDialog fileDialog( coreWidget_,
                            tr("Load Settings"),
                            OpenFlipper::Options::currentDirStr(),
                            tr("INI files (*.ini);;OBJ files (*.obj )") );

531
    fileDialog.setOption (QFileDialog::DontUseNativeDialog, true);
532
533
534
535
536
537
538
    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 ) );
539
    optionsBox->setTitle(tr("Options"));
540
541
542
    layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );

    QCheckBox *loadProgramSettings = new QCheckBox(optionsBox);
543
544
    loadProgramSettings->setText(tr("Load program settings"));
    loadProgramSettings->setToolTip(tr("Load all current program settings from the file ( This will include view settings, colors,...) "));
545
546
547
    loadProgramSettings->setCheckState( Qt::Unchecked );

    QCheckBox *loadPluginSettings = new QCheckBox(optionsBox);
548
549
    loadPluginSettings->setText(tr("Load per Plugin Settings"));
    loadPluginSettings->setToolTip(tr("Plugins should load their current global settings from the file"));
550
551
552
    loadPluginSettings->setCheckState( Qt::Checked );

    QCheckBox *loadObjectInfo = new QCheckBox(optionsBox);
553
554
    loadObjectInfo->setText(tr("Load all objects defined in the file"));
    loadObjectInfo->setToolTip(tr("Load all objects which are defined in the file"));
555
556
557
558
559
560
561
562
    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
563
564
    fileDialog.resize(550 ,500);

565
566
567
568
569
570
571
572
573
574
575
576
    // ========================================================================================
    // 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;
577
      return;
578
579
580
581
    }

    complete_name = fileNames[0];

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

583
584
    QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
    OpenFlipper::Options::currentDir(newpath);
Jan Möbius's avatar
Jan Möbius committed
585

586
    if ( complete_name.endsWith("ini") ) {
587
588
589
590
      openIniFile( complete_name,
                   loadProgramSettings->isChecked(),
                   loadPluginSettings->isChecked(),
                   loadObjectInfo->isChecked());
591
592
      if ( loadProgramSettings->isChecked() )
        applyOptions();
593
594
    } else if ( complete_name.endsWith("obj") ) {
      openObjFile(complete_name);
595
596
      if ( loadProgramSettings->isChecked() )
        applyOptions();
597
    }
Jan Möbius's avatar
Jan Möbius committed
598

599
600
601
    coreWidget_->addRecent(complete_name, DATA_NONE);
  }
}
Jan Möbius's avatar
 
Jan Möbius committed
602

603
604
/// Load settings from file
void Core::loadSettings(QString _filename){
Jan Möbius's avatar
Jan Möbius committed
605

606
  if ( !QFile(_filename).exists() )
Jan Möbius's avatar
 
Jan Möbius committed
607
608
    return;

609
  QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
Jan Möbius's avatar
 
Jan Möbius committed
610
611
  OpenFlipper::Options::currentDir(newpath);

612
  if ( _filename.endsWith("ini") ) {
613
    // Loaded function for recent files. Load everything.
614
    openIniFile(_filename,true,true,true);
Jan Möbius's avatar
 
Jan Möbius committed
615
    applyOptions();
616
617
  } else if ( _filename.endsWith("obj") ) {
    openObjFile(_filename);
Jan Möbius's avatar
 
Jan Möbius committed
618
619
620
621
    applyOptions();
  }

}