Commit 71ce0ee6 authored by Dirk Wilden's avatar Dirk Wilden

updates for loading files

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8175 383ad7c9-94d9-4d36-a494-682f7c89f535
parent d56ce192
...@@ -154,6 +154,22 @@ public slots: ...@@ -154,6 +154,22 @@ public slots:
*/ */
virtual int loadObject(QString /*_filename*/) = 0; 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 /** \brief Save an object from the given file
* *
* The Core will call this slot if you should save an object to a file. * The Core will call this slot if you should save an object to a file.
......
...@@ -892,14 +892,10 @@ Core::slotRecentOpen(QAction* _action) ...@@ -892,14 +892,10 @@ Core::slotRecentOpen(QAction* _action)
QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles(); QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles();
for (int i = 0 ; i < recentFiles.size() ; ++i ) for (int i = 0 ; i < recentFiles.size() ; ++i )
if ( recentFiles[i].filename == _action->text() ){ if ( recentFiles[i].filename == _action->text() ){
if (recentFiles[i].type == DATA_UNKNOWN)
loadSettings( recentFiles[i].filename );
else{
OpenFlipper::Options::loadingRecentFile(true); OpenFlipper::Options::loadingRecentFile(true);
loadObject(recentFiles[i].type, recentFiles[i].filename); loadObject(recentFiles[i].type, recentFiles[i].filename);
OpenFlipper::Options::loadingRecentFile(false); OpenFlipper::Options::loadingRecentFile(false);
} return;
break;
} }
} }
......
...@@ -114,6 +114,7 @@ struct fileTypes { ...@@ -114,6 +114,7 @@ struct fileTypes {
QString loadFilters; QString loadFilters;
QString saveFilters; QString saveFilters;
FileInterface* plugin; FileInterface* plugin;
QObject* object;
}; };
struct dataTypes { struct dataTypes {
......
...@@ -1144,6 +1144,7 @@ void Core::loadPlugin(QString filename, bool silent){ ...@@ -1144,6 +1144,7 @@ void Core::loadPlugin(QString filename, bool silent){
ft.loadFilters = filePlugin->getLoadFilters(); ft.loadFilters = filePlugin->getLoadFilters();
ft.saveFilters = filePlugin->getSaveFilters(); ft.saveFilters = filePlugin->getSaveFilters();
ft.plugin = filePlugin; ft.plugin = filePlugin;
ft.object = plugin;
supportedTypes_.push_back(ft); supportedTypes_.push_back(ft);
} }
......
...@@ -199,8 +199,41 @@ int Core::loadObject ( QString _filename ) { ...@@ -199,8 +199,41 @@ int Core::loadObject ( QString _filename ) {
if (_filename.endsWith(".ofs")) { if (_filename.endsWith(".ofs")) {
emit log(LOGINFO ,tr("Starting script execution of %1.").arg( _filename)) ; emit log(LOGINFO ,tr("Starting script execution of %1.").arg( _filename)) ;
emit executeFileScript(_filename); emit executeFileScript(_filename);
} else } else {
return loadObject( DATA_TRIANGLE_MESH, _filename);
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; return -1;
} }
...@@ -214,18 +247,30 @@ int Core::loadObject( DataType _type, QString _filename) { ...@@ -214,18 +247,30 @@ int Core::loadObject( DataType _type, QString _filename) {
if (_type == DATA_UNKNOWN) if (_type == DATA_UNKNOWN)
return loadObject(_filename); return loadObject(_filename);
QFileInfo fi(_filename);
for (int i=0; i < (int)supportedTypes_.size(); i++) 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() ) { if ( OpenFlipper::Options::gui() ) {
coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename)); coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
if ( !OpenFlipper::Options::loadingSettings() ) if ( !OpenFlipper::Options::loadingSettings() )
coreWidget_->setStatus(ApplicationStatus::PROCESSING ); coreWidget_->setStatus(ApplicationStatus::PROCESSING );
} }
int id = -1;
//load file //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 ( OpenFlipper::Options::gui() ) {
if ( id != -1 ) if ( id != -1 )
...@@ -239,6 +284,9 @@ int Core::loadObject( DataType _type, QString _filename) { ...@@ -239,6 +284,9 @@ int Core::loadObject( DataType _type, QString _filename) {
return id; return id;
} }
emit log(LOGERR, tr("Unable to load object. No suitable plugin found!") );
return -1; //no plugin found return -1; //no plugin found
} }
...@@ -343,14 +391,31 @@ void Core::slotLoad(QString _filename, int _pluginID) { ...@@ -343,14 +391,31 @@ void Core::slotLoad(QString _filename, int _pluginID) {
BaseObjectData* object; BaseObjectData* object;
PluginFunctions::getObject(id,object); PluginFunctions::getObject(id,object);
if ( !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 // 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. // If the id was greater than zero, add the file to the recent files.
...@@ -425,9 +490,9 @@ void Core::slotObjectOpened ( int _id ) { ...@@ -425,9 +490,9 @@ void Core::slotObjectOpened ( int _id ) {
PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) ); PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) );
if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 ) if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
PluginFunctions::orthographicProjection(i); PluginFunctions::orthographicProjection(i);
else else
PluginFunctions::perspectiveProjection(i); PluginFunctions::perspectiveProjection(i);
PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i ); PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
} }
...@@ -694,7 +759,7 @@ void Core::loadSettings(){ ...@@ -694,7 +759,7 @@ void Core::loadSettings(){
if ( loadProgramSettings->isChecked() ) if ( loadProgramSettings->isChecked() )
applyOptions(); applyOptions();
} else if ( complete_name.endsWith("obj") ) { } else if ( complete_name.endsWith("obj") ) {
openObjFile(complete_name); loadObject(complete_name);
if ( loadProgramSettings->isChecked() ) if ( loadProgramSettings->isChecked() )
applyOptions(); applyOptions();
} }
...@@ -717,7 +782,7 @@ void Core::loadSettings(QString _filename){ ...@@ -717,7 +782,7 @@ void Core::loadSettings(QString _filename){
openIniFile(_filename,true,true,true); openIniFile(_filename,true,true,true);
applyOptions(); applyOptions();
} else if ( _filename.endsWith("obj") ) { } else if ( _filename.endsWith("obj") ) {
openObjFile(_filename); loadObject(_filename);
applyOptions(); applyOptions();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment