diff --git a/BasePlugin/FileInterface.hh b/BasePlugin/FileInterface.hh index da63a9de646c436791d3c702853d6e5371dfba69..fa4d54379b61d4b698ee4b0ebb4afc88bf34a1f0 100644 --- a/BasePlugin/FileInterface.hh +++ b/BasePlugin/FileInterface.hh @@ -154,6 +154,22 @@ public slots: */ virtual int loadObject(QString /*_filename*/) = 0; + /** \brief Load an object from the given file + * + * The Core will call this slot if you should load a file. The core will + * check if you support the given file type depending on the provided + * filters and dataTypes ( see supportedType and getLoadFilters )\n + * + * if you just opened a file and did not create any object, return 0 here, + * telling the core that it was successfully loaded but no new object + * has been created! + * + * If the Plugin is able to open the file in different DataTypes + * one of these DataTypes can be forced here + * + */ + virtual int loadObject(QString /*_filename*/, DataType /*_type*/){ return -1;}; + /** \brief Save an object from the given file * * The Core will call this slot if you should save an object to a file. diff --git a/Core/Core.cc b/Core/Core.cc index 003bc4639bff44c0cae8caf10835242f295940d0..23e02351ecfe3cd7dd54d8aafd6a9d7359747a67 100644 --- a/Core/Core.cc +++ b/Core/Core.cc @@ -892,14 +892,10 @@ Core::slotRecentOpen(QAction* _action) QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles(); for (int i = 0 ; i < recentFiles.size() ; ++i ) if ( recentFiles[i].filename == _action->text() ){ - if (recentFiles[i].type == DATA_UNKNOWN) - loadSettings( recentFiles[i].filename ); - else{ OpenFlipper::Options::loadingRecentFile(true); loadObject(recentFiles[i].type, recentFiles[i].filename); OpenFlipper::Options::loadingRecentFile(false); - } - break; + return; } } diff --git a/Core/Core.hh b/Core/Core.hh index d411d31b9726fc660c4ef0c34534ea1cb05dcb94..55b36807d852b204ce526674162e1548f3ea9d68 100644 --- a/Core/Core.hh +++ b/Core/Core.hh @@ -114,6 +114,7 @@ struct fileTypes { QString loadFilters; QString saveFilters; FileInterface* plugin; + QObject* object; }; struct dataTypes { diff --git a/Core/PluginLoader.cc b/Core/PluginLoader.cc index f42e55d940620dd5174f2b4fa545f5d4d6c94011..6694862edb7da54db41dabf60ba52a57ac7bac39 100644 --- a/Core/PluginLoader.cc +++ b/Core/PluginLoader.cc @@ -1144,6 +1144,7 @@ void Core::loadPlugin(QString filename, bool silent){ ft.loadFilters = filePlugin->getLoadFilters(); ft.saveFilters = filePlugin->getSaveFilters(); ft.plugin = filePlugin; + ft.object = plugin; supportedTypes_.push_back(ft); } diff --git a/Core/openFunctions.cc b/Core/openFunctions.cc index 15c14c6263b6729d3de2480474755fd0f624ada8..df3a108d5b24552600cbc3b67389698249216d38 100644 --- a/Core/openFunctions.cc +++ b/Core/openFunctions.cc @@ -199,8 +199,41 @@ int Core::loadObject ( QString _filename ) { if (_filename.endsWith(".ofs")) { emit log(LOGINFO ,tr("Starting script execution of %1.").arg( _filename)) ; emit executeFileScript(_filename); - } else - return loadObject( DATA_TRIANGLE_MESH, _filename); + } else { + + QFileInfo fi(_filename); + + for (int i=0; i < (int)supportedTypes_.size(); i++){ + + QString filters = supportedTypes_[i].plugin->getLoadFilters(); + //check extension + if ( ! filters.contains( "*." + fi.completeSuffix() ) ) + continue; + + 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() ) { + 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 ); + } + + return id; + } + } + + emit log(LOGERR, tr("Unable to load object (type unknown). No suitable plugin found!") ); return -1; } @@ -214,18 +247,30 @@ int Core::loadObject( DataType _type, QString _filename) { if (_type == DATA_UNKNOWN) return loadObject(_filename); + QFileInfo fi(_filename); + for (int i=0; i < (int)supportedTypes_.size(); i++) - if (supportedTypes_[i].type == _type) { - + if (supportedTypes_[i].type & _type || supportedTypes_[i].type == _type) { + QString filters = supportedTypes_[i].plugin->getLoadFilters(); + //check extension + if ( ! filters.contains( "*." + fi.completeSuffix() ) ) + continue; + + if ( OpenFlipper::Options::gui() ) { coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename)); if ( !OpenFlipper::Options::loadingSettings() ) coreWidget_->setStatus(ApplicationStatus::PROCESSING ); } + int id = -1; + //load file - int id = supportedTypes_[i].plugin->loadObject(_filename); + if ( checkSlot( supportedTypes_[i].object , "loadObject(QString,DataType)" ) ) + id = supportedTypes_[i].plugin->loadObject(_filename, _type); + else + id = supportedTypes_[i].plugin->loadObject(_filename); if ( OpenFlipper::Options::gui() ) { if ( id != -1 ) @@ -239,6 +284,9 @@ int Core::loadObject( DataType _type, QString _filename) { return id; } + + emit log(LOGERR, tr("Unable to load object. No suitable plugin found!") ); + return -1; //no plugin found } @@ -343,14 +391,31 @@ void Core::slotLoad(QString _filename, int _pluginID) { BaseObjectData* object; PluginFunctions::getObject(id,object); - + if ( !object ) { - emit log(LOGERR,tr("Object id returned but no object with this id has been found! Error in one of the file plugins!")); - return; + + BaseObject* baseObj = 0; + GroupObject* group = 0; + + PluginFunctions::getObject(id,baseObj); + + if (baseObj){ + + group = dynamic_cast< GroupObject* > (baseObj); + + if (group) + type = DATA_UNKNOWN; + } + + 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; + } } // Get the objects type - type = object->dataType(); + if (object) + type = object->dataType(); } // If the id was greater than zero, add the file to the recent files. @@ -425,9 +490,9 @@ void Core::slotObjectOpened ( int _id ) { PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) ); if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 ) - PluginFunctions::orthographicProjection(i); + PluginFunctions::orthographicProjection(i); else - PluginFunctions::perspectiveProjection(i); + PluginFunctions::perspectiveProjection(i); PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i ); } @@ -694,7 +759,7 @@ void Core::loadSettings(){ if ( loadProgramSettings->isChecked() ) applyOptions(); } else if ( complete_name.endsWith("obj") ) { - openObjFile(complete_name); + loadObject(complete_name); if ( loadProgramSettings->isChecked() ) applyOptions(); } @@ -717,7 +782,7 @@ void Core::loadSettings(QString _filename){ openIniFile(_filename,true,true,true); applyOptions(); } else if ( _filename.endsWith("obj") ) { - openObjFile(_filename); + loadObject(_filename); applyOptions(); }