Commit d3c89a4d authored by Dirk Wilden's avatar Dirk Wilden

load/save routine changed.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7639 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3de3e022
......@@ -111,6 +111,7 @@
//== CLASS DEFINITION =========================================================
struct fileTypes {
QString name;
DataType type;
QString loadFilters;
QString saveFilters;
......@@ -315,6 +316,9 @@ signals:
/// A plugin wants to load a given file
void slotLoad(QString _filename, DataType _type, int& _id);
/// the load widget wants to load a given file
void slotLoad(QString _filename, int _pluginID);
/// Called when a file has been opened
void slotObjectOpened ( int _id );
......@@ -511,6 +515,8 @@ private:
* @param _id id of the object
*/
bool saveObject( int _id, QString _filename );
void saveObject( int _id, QString _filename, int _pluginID );
/** Show dialog for saving an object to a new location
* @param _id id of the object
......@@ -806,6 +812,9 @@ private:
/// Set the active ViewMode
void setViewMode(QString _viewMode);
/// Set the icon of a viewMode
void setViewModeIcon(QString _mode, QString _iconName);
private :
/// Core scripting engine
QScriptEngine scriptEngine_;
......
......@@ -1136,6 +1136,7 @@ void Core::loadPlugin(QString filename, bool silent){
// Collect supported Data from file plugin
fileTypes ft;
ft.name = basePlugin->name();
ft.type = filePlugin->supportedType();
ft.loadFilters = filePlugin->getLoadFilters();
ft.saveFilters = filePlugin->getSaveFilters();
......
......@@ -275,6 +275,81 @@ void Core::slotCopyObject( int _oldId , int& _newId ) {
}
/// 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 );
}
BaseObjectData* object;
PluginFunctions::getObject(id,object);
DataType type = object->dataType();
// Check if it is a polymesh
if ( object != 0 && 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;
}
}
}
}
if ( id >= 0 )
if ( OpenFlipper::Options::gui() )
coreWidget_->addRecent(_filename, type);
}
/// Slot for loading a given file
void Core::slotLoad(QString _filename, DataType _type, int& _id) {
_id = loadObject(_type,_filename);
......@@ -499,8 +574,8 @@ void Core::loadObject() {
if (supportedTypes_.size() != 0){
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)));
connect(widget,SIGNAL(load(QString, int)),this,SLOT(slotLoad(QString, int)));
connect(widget,SIGNAL(save(int, QString, int)),this,SLOT(saveObject(int, QString, int)));
widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
......
......@@ -99,6 +99,42 @@ bool Core::saveObject( int _id, QString _filename ) {
//-----------------------------------------------------------------------------------------------------
/// Save an object
/// get object with given id, find a plugin to save dataType, save!
/// (existing files will be overwritten)
void Core::saveObject( int _id, QString _filename, int _pluginID ) {
BaseObjectData* object;
PluginFunctions::getObject(_id,object);
if ( OpenFlipper::Options::gui() ) {
coreWidget_->statusMessage( tr("Saving ") + _filename + " ...");
if ( !OpenFlipper::Options::savingSettings() )
coreWidget_->setStatus(ApplicationStatus::PROCESSING );
}
//save object
bool ok = supportedTypes_[_pluginID].plugin->saveObject(_id,_filename);
if ( OpenFlipper::Options::gui() ) {
if (ok)
coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... done"), 4000 );
else
coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... failed!"), 4000 );
if ( !OpenFlipper::Options::savingSettings() )
coreWidget_->setStatus(ApplicationStatus::READY );
}
//add to recent files
if (ok && !OpenFlipper::Options::savingSettings()
&& OpenFlipper::Options::gui() )
coreWidget_->addRecent( _filename, object->dataType() );
}
//-----------------------------------------------------------------------------------------------------
/// Save an object to a new location
/// Show the save-widget to determine a filename, the widget calls slotSave to save the object
bool Core::saveObjectTo( int _id, QString _filename ) {
......@@ -114,8 +150,8 @@ bool Core::saveObjectTo( int _id, QString _filename ) {
LoadWidget* widget = new LoadWidget(supportedTypes_);
widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
connect(widget,SIGNAL(load(QString, DataType, int&)),this,SLOT(slotLoad(QString, DataType, int&)));
connect(widget,SIGNAL(save(int, QString)),this,SLOT(saveObject(int, QString)));
connect(widget,SIGNAL(load(QString, int)),this,SLOT(slotLoad(QString, int)));
connect(widget,SIGNAL(save(int, QString, int)),this,SLOT(saveObject(int, QString, int)));
if (supportedTypes_.size() != 0)
result = widget->showSave(_id,_filename);
......
......@@ -130,6 +130,26 @@ void Core::setViewMode(QString _viewMode){
//-----------------------------------------------------------------------------
void Core::setViewModeIcon(QString _mode, QString _iconName){
if ( OpenFlipper::Options::gui() ){
QFile file(_iconName);
QFileInfo fileInfo(file);
if ( ! file.exists() ){
emit log(LOGERR, tr("Icon not found (%1)").arg(_iconName) );
return;
}
file.copy(OpenFlipper::Options::configDirStr() + QDir::separator() + "Icons" + QDir::separator() + "viewMode_" + fileInfo.fileName() );
coreWidget_->slotSetViewModeIcon( _mode, "viewMode_" + fileInfo.fileName() );
}
}
//-----------------------------------------------------------------------------
void Core::addViewModeToolboxes(QString _modeName, QString _toolboxList) {
QStringList list = _toolboxList.split(";");
......
#include "FileOptionsDialog.hh"
#include <OpenFlipper/INIFile/INIFile.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <QVBoxLayout>
#include <QGridLayout>
FileOptionsDialog::FileOptionsDialog(std::vector<fileTypes>& _supportedTypes, QStringList _extensions, bool _loadMode, QWidget *parent)
: QDialog(parent),
ext_(_extensions),
supportedTypes_(_supportedTypes),
loadMode_(_loadMode)
{
ext_.removeDuplicates();
QGridLayout* grid = new QGridLayout;
QVector< int > usefulPlugins;
//check if more than one plugin is able to handle this extension
for (int i=0; i < ext_.size(); i++){
int count = 0;
QStringList names;
for (uint t=0; t < supportedTypes_.size(); t++){
QString filters;
if (loadMode_)
filters = supportedTypes_[t].loadFilters;
else
filters = supportedTypes_[t].saveFilters;
if (filters.contains(ext_[i])){
count++;
names.push_back( supportedTypes_[t].name );
usefulPlugins.push_back( t );
}
}
//more than one plugin can handle the extension
if (count > 1){
QLabel* label = new QLabel( tr("For *.%1 use plugin ").arg(ext_[i]) );
QComboBox* box = new QComboBox();
box->addItems(names);
box->setAccessibleName(ext_[i]);
grid->addWidget(label, grid->rowCount(), 0);
grid->addWidget(box, grid->rowCount()-1, 1);
connect(box, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotPluginChanged(QString)) );
boxes_.push_back(box);
}
}
//load defaults from ini file
QString filename = OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini";
INIFile ini;
if ( ! ini.connect(filename,false) ) {
std::cerr << (tr("Failed to connect to ini file %1").arg(filename)).toStdString() << std::endl;
return;
}
for (int i=0; i < boxes_.count(); i++){
QString pluginName;
if ( ini.get_entry(pluginName, "Options" , "Extension_" + _extensions[i] ) ){
for (int t=0; t < (boxes_[i])->count(); t++)
if ( (boxes_[i])->itemText(t) == pluginName ){
(boxes_[i])->setCurrentIndex(t);
break;
}
}
}
// close ini file
ini.disconnect();
QGroupBox* group = new QGroupBox(tr("Extensions with multiple plugins"));
group->setLayout(grid);
if (boxes_.count() == 0)
group->setVisible(false);
//add option widgets from all fileplugins
for (uint t=0; t < supportedTypes_.size(); t++){
if ( !usefulPlugins.contains(t) )
continue;
QWidget* widget;
if (loadMode_)
widget = supportedTypes_[t].plugin->loadOptionsWidget("");
else
widget = supportedTypes_[t].plugin->saveOptionsWidget("");
if (widget != 0)
tabs_.addTab(widget, supportedTypes_[t].name);
}
//add buttons at bottom
QPushButton* cancel = new QPushButton(tr("&Cancel"));
QPushButton* makeDef = new QPushButton(tr("Make &Default"));
QPushButton* ok = new QPushButton(tr("&Ok"));
QHBoxLayout* buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(cancel);
buttonLayout->addWidget(makeDef);
buttonLayout->addStretch();
buttonLayout->addWidget(ok);
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(group);
layout->addWidget(&tabs_);
layout->addLayout(buttonLayout);
setLayout(layout);
connect( cancel, SIGNAL(clicked()), this, SLOT(reject()) );
connect( ok, SIGNAL(clicked()), this, SLOT(accept()) );
connect(makeDef, SIGNAL(clicked()), this, SLOT(slotMakeDefault()) );
}
FileOptionsDialog::~FileOptionsDialog()
{
//remove tabs
for (int i=tabs_.count()-1; i >= 0; i--)
tabs_.removeTab(i);
//and set parent of widgets to NULL
for (uint t=0; t < supportedTypes_.size(); t++){
QWidget* widget;
if (loadMode_)
widget = supportedTypes_[t].plugin->loadOptionsWidget("");
else
widget = supportedTypes_[t].plugin->saveOptionsWidget("");
if (widget != 0)
widget->setParent(0);
}
}
void FileOptionsDialog::slotPluginChanged(QString _name){
QComboBox* box = dynamic_cast<QComboBox*>(QObject::sender());
for (uint t=0; t < supportedTypes_.size(); t++)
if ( supportedTypes_[t].name == _name ){
emit setPluginForExtension(box->accessibleName(), t ); //accessibleName contains the extension
break;
}
}
void FileOptionsDialog::slotMakeDefault(){
QString filename = OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini";
INIFile ini;
if ( ! ini.connect(filename,false) ) {
std::cerr << (tr("Failed to connect to ini file %1").arg(filename)).toStdString() << std::endl;
return;
}
for (int i=0; i < boxes_.count(); i++)
ini.add_entry("Options","Extension_" + (boxes_[i])->accessibleName(), boxes_[i]->currentText() );
// close ini file
ini.disconnect();
}
/*===========================================================================*\
* *
* 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/>. *
* *
\*===========================================================================*/
#include <QtGui>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/Core/Core.hh>
class FileOptionsDialog : public QDialog
{
Q_OBJECT
public:
FileOptionsDialog(std::vector<fileTypes>& _supportedTypes, QStringList _extensions, bool _loadMode, QWidget *parent = 0 );
~FileOptionsDialog();
private:
QStringList ext_;
std::vector<fileTypes>& supportedTypes_;
QTabWidget tabs_;
private slots:
void slotPluginChanged(QString _name);
void slotMakeDefault();
signals:
void setPluginForExtension(QString _extension, int _pluginId );
private:
bool loadMode_;
QVector< QComboBox* > boxes_;
};
\ No newline at end of file
This diff is collapsed.
......@@ -48,6 +48,7 @@
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/Core/Core.hh>
#include <map>
class LoadWidget : public QFileDialog
{
......@@ -57,13 +58,13 @@ class LoadWidget : public QFileDialog
~LoadWidget();
signals:
void load(QString _filename, DataType _type, int& _id);
void save(int _id, QString _filename);
void load(QString _filename, int _pluginID);
void save(int _id, QString _filename, int _pluginID);
private slots:
void slotSetLoadFilters(int _typeIndex);
void slotSetSaveFilters(int _typeIndex);
void currentFilterChanged(QString _currentFilter);
void slotSetPluginForExtension(QString _extension, int _pluginId );
void slotSetLoadFilters();
void slotSetSaveFilters(DataType _type);
private:
int id_;
......@@ -71,7 +72,7 @@ class LoadWidget : public QFileDialog
QStringList lastPaths;
std::vector<fileTypes>& supportedTypes_;
void getPluginForExtensionINI(QStringList _extensions);
public:
int showLoad();
......@@ -84,14 +85,11 @@ class LoadWidget : public QFileDialog
void loadFile();
void saveFile();
/// combo box for choosing file type to load/save
QComboBox* typeBox_;
/// QFrame on the right
QGroupBox* box_;
QHBoxLayout* boxLayout_;
QVector< QWidget* > boxWidgets_;
/// checkbox for option displaying
QCheckBox* optionsBox_;
std::map< QString, int > pluginForExtension_;
bool step_;
};
......
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