Skip to content
Snippets Groups Projects
Commit 71ce0ee6 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

updates for loading files

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8175 383ad7c9-94d9-4d36-a494-682f7c89f535
parent d56ce192
Branches
Tags
No related merge requests found
......@@ -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.
......
......@@ -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;
}
}
......
......@@ -114,6 +114,7 @@ struct fileTypes {
QString loadFilters;
QString saveFilters;
FileInterface* plugin;
QObject* object;
};
struct dataTypes {
......
......@@ -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);
}
......
......@@ -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,8 +247,15 @@ 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() ) {
......@@ -224,8 +264,13 @@ int Core::loadObject( DataType _type, QString _filename) {
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
}
......@@ -345,11 +393,28 @@ void Core::slotLoad(QString _filename, int _pluginID) {
PluginFunctions::getObject(id,object);
if ( !object ) {
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
if (object)
type = object->dataType();
}
......@@ -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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment