Commit 19c7a8b8 authored by Dirk Wilden's avatar Dirk Wilden

fixed and cleaned up saveFunctions

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3580 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ef35d1d0
......@@ -172,12 +172,12 @@ Core::init() {
coreWidget_ = new CoreWidget(viewModes_ , plugins);
connect(coreWidget_, SIGNAL(clearAll()) , this, SLOT(clearAll()));
connect(coreWidget_, SIGNAL(loadMenu()) , this, SLOT(slotLoadMenu()));
connect(coreWidget_, SIGNAL(loadMenu()) , this, SLOT(loadObject()));
connect(coreWidget_, SIGNAL(addEmptyObjectMenu()) , this, SLOT(slotAddEmptyObjectMenu()));
connect(coreWidget_, SIGNAL(saveMenu()) , this, SLOT(slotSaveMenu()));
connect(coreWidget_, SIGNAL(saveToMenu()) , this, SLOT(slotSaveToMenu()));
connect(coreWidget_, SIGNAL(loadIniMenu()) , this, SLOT(slotLoadIniMenu()));
connect(coreWidget_, SIGNAL(saveIniMenu()) , this, SLOT(slotSaveIniMenu()));
connect(coreWidget_, SIGNAL(saveMenu()) , this, SLOT(saveAllObjects()));
connect(coreWidget_, SIGNAL(saveToMenu()) , this, SLOT(saveAllObjectsTo()));
connect(coreWidget_, SIGNAL(loadIniMenu()) , this, SLOT(loadSettings()));
connect(coreWidget_, SIGNAL(saveIniMenu()) , this, SLOT(saveSettings()));
connect(coreWidget_, SIGNAL(applyOptions()) , this, SLOT(applyOptions()));
connect(coreWidget_, SIGNAL(saveOptions()) , this, SLOT(saveOptions()));
connect(coreWidget_, SIGNAL(recentOpen(QAction*)) , this, SLOT(slotRecentOpen(QAction*)));
......@@ -577,7 +577,7 @@ void Core::updateView() {
}
if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::openingIni() && !OpenFlipper::Options::redrawDisabled() ) {
if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() && !OpenFlipper::Options::redrawDisabled() ) {
coreWidget_->examiner_widget_->sceneGraph(root_node_scenegraph_);
coreWidget_->examiner_widget_->updateGL();
}
......@@ -977,6 +977,24 @@ void Core::setDescriptions(){
emit setSlotDescription("writeVersionNumbers(QString)", "write the current versions of all plugins to INI file",
QStringList("filename"),
QStringList("fullpath to a file where the versions should be written to."));
//save slots
emit setSlotDescription("saveObject(int,QString)", "Save object to file. If the file exists it will be overwritten.",
QString("object-id,filename").split(","),
QString("id of the object, complete path and filename").split(","));
emit setSlotDescription("saveObjectTo(int,QString)", "Save object to file. The location can be chosen in a dialog. "
"(only works if GUI is available)",
QString("object-id,filename").split(","),
QString("id of the object, initial filename for the dialog").split(","));
emit setSlotDescription("saveAllObjects()", "Saves all opened objects. Before overwriting the user is asked. "
"If no filename is available a dialog is shown. (only works if GUI is available)",QStringList(), QStringList());
emit setSlotDescription("saveAllObjectsTo()", "Saves all opened objects. The locations can be chosen in dialogs. "
"(only works if GUI is available)",QStringList(), QStringList());
emit setSlotDescription("saveSettings()", "Show the dialog to save the current setting. (only works if GUI is available)",QStringList(), QStringList());
//load slots
emit setSlotDescription("loadObject()", "Show the dialog to load an object. (only works if GUI is available)",QStringList(), QStringList());
emit setSlotDescription("loadSettings()", "Show the dialog to load settings. (only works if GUI is available)",QStringList(), QStringList());
emit setSlotDescription("loadSettings(QString)", "load settings from file.",QStringList(), QStringList());
}
// //-----------------------------------------------------------------------------
//
......
......@@ -241,9 +241,6 @@ signals:
/// A plugin wants to load a given file
void slotLoad(QString _filename, DataType _type, int& _id);
/// A plugin wants to save an object;
void slotSave(int _id , QString _filename);
/// Called when a file has been opened
void slotObjectOpened ( int _id );
......@@ -350,16 +347,43 @@ private:
*/
int loadObject( DataType _type, QString _filename);
/** Save object with given id
* @param _id id of the object
*/
bool saveObject( int _id, QString _filename );
/** @} */
/** Show dialog for saving an object to a new location
* @param _id id of the object
* @param _filename current filename of the object
*/
bool saveObjectTo( int _id, QString _filename );
//===========================================================================
/** @name Load / Save slots
* @{ */
//===========================================================================
public slots:
/** Save object with given id
* @param _id id of the object
*/
bool saveObject( int _id, QString _filename );
/** Show dialog for saving an object to a new location
* @param _id id of the object
* @param _filename current filename of the object
*/
bool saveObjectTo( int _id, QString _filename );
/// Slot for saving objects from Menu
void saveAllObjects();
/// Slot for saving objects to a new location
void saveAllObjectsTo();
/// Save current status to a settings file
void saveSettings();
/// Open Load Widget
void loadObject();
/// Load status from file
void loadSettings();
/// Load status from file
void loadSettings(QString _filename);
/** @} */
......@@ -384,24 +408,9 @@ private:
/// Slot adding empty object from Menu of a given type
void slotAddEmptyObject( DataType _type , int& _id );
/// Slot for saving objects from Menu
void slotSaveMenu();
/// Slot for saving objects to a new location
void slotSaveToMenu();
/// Load status from ini file
void slotLoadIniMenu();
/// Save current status to ini file
void slotSaveIniMenu();
/// Exit Application
void slotExit();
/// Open Load Widget
void slotLoadMenu();
/// Open Recent file
void slotRecentOpen(QAction* _action);
......
......@@ -427,7 +427,7 @@ void Core::openIniFile(QString _filename) {
coreWidget_->setStatus(ApplicationStatus::BLOCKED );
}
OpenFlipper::Options::openingIni(true);
OpenFlipper::Options::loadingSettings(true);
readApplicationOptions(ini);
......@@ -492,7 +492,7 @@ void Core::openIniFile(QString _filename) {
ini.disconnect();
OpenFlipper::Options::openingIni(false);
OpenFlipper::Options::loadingSettings(false);
resetScenegraph();
......
......@@ -75,7 +75,7 @@ void Core::openObjFile(QString _filename)
coreWidget_->setStatus(ApplicationStatus::BLOCKED );
}
OpenFlipper::Options::openingIni(true);
OpenFlipper::Options::loadingSettings(true);
while(!in.eof())
......@@ -112,7 +112,7 @@ void Core::openObjFile(QString _filename)
}
OpenFlipper::Options::openingIni(false);
OpenFlipper::Options::loadingSettings(false);
resetScenegraph();
......
......@@ -800,7 +800,7 @@ void Core::loadPlugin(QString filename, bool silent){
this , SLOT(slotLoad( QString,DataType,int& )),Qt::DirectConnection );
if ( checkSignal(plugin,"save(int,QString)" ) )
connect(plugin , SIGNAL( save(int,QString) ) ,
this , SLOT( slotSave(int,QString) ), Qt::DirectConnection);
this , SLOT( saveObject(int,QString) ), Qt::DirectConnection);
if ( checkSlot( plugin , "fileOpened(int)" ) )
connect(this , SIGNAL( openedFile( int) ) ,
......
......@@ -44,7 +44,7 @@
#include "OpenFlipper/widgets/addEmptyWidget/addEmptyWidget.hh"
void Core::resetScenegraph() {
if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::openingIni() ) {
if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() ) {
// update scene graph
coreWidget_->examiner_widget_->lockUpdate();
coreWidget_->examiner_widget_->sceneGraph(root_node_scenegraph_);
......@@ -121,7 +121,7 @@ int Core::loadObject( DataType _type, QString _filename) {
if ( OpenFlipper::Options::gui() ) {
coreWidget_->statusMessage( "Loading " + _filename + " ...");
if ( !OpenFlipper::Options::openingIni() )
if ( !OpenFlipper::Options::loadingSettings() )
coreWidget_->setStatus(ApplicationStatus::PROCESSING );
}
......@@ -134,7 +134,7 @@ int Core::loadObject( DataType _type, QString _filename) {
else
coreWidget_->statusMessage( "Loading " + _filename + " ... failed!", 4000 );
if ( !OpenFlipper::Options::openingIni() )
if ( !OpenFlipper::Options::loadingSettings() )
coreWidget_->setStatus(ApplicationStatus::READY );
}
......@@ -248,45 +248,75 @@ void Core::slotAddEmptyObjectMenu() {
emit log(LOGERR,"Could not show 'add Empty' dialog. Missing file-plugins.");
}
//========================================================================================
// === Public Slots ============================
//========================================================================================
/// Open Load-Object Widget
void Core::slotLoadMenu() {
if (supportedTypes_.size() != 0){
static LoadWidget* widget = 0;
void Core::loadObject() {
if ( OpenFlipper::Options::gui() ){
if (supportedTypes_.size() != 0){
static LoadWidget* widget = 0;
// Open Widget
if ( !widget ){
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)));
}
widget->showLoad();
}else
emit log(LOGERR,"Could not show 'load objects' dialog. Missing file-plugins.");
// Open Widget
if ( !widget ){
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(slotSave(int, QString)));
}
widget->showLoad();
}else
emit log(LOGERR,"Could not show 'load objects' dialog. Missing file-plugins.");
}
}
/// Load settings from ini-file
void Core::slotLoadIniMenu(){
QString complete_name;
/// Load settings from file
void Core::loadSettings(){
if ( OpenFlipper::Options::gui() ){
QString complete_name;
complete_name = ACG::getOpenFileName(coreWidget_,
tr("Load Settings"),
tr("INI files (*.ini);;OBJ files (*.obj)"),
OpenFlipper::Options::currentDirStr());
if (complete_name.isEmpty())
return;
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath);
if ( complete_name.endsWith("ini") ) {
openIniFile(complete_name);
applyOptions();
} else if ( complete_name.endsWith("obj") ) {
openObjFile(complete_name);
applyOptions();
}
coreWidget_->addRecent(complete_name, DATA_NONE);
}
}
complete_name = ACG::getOpenFileName(coreWidget_,
tr("Load Settings"),
tr("INI files (*.ini);;OBJ files (*.obj)"),
OpenFlipper::Options::currentDirStr());
if (complete_name.isEmpty())
/// Load settings from file
void Core::loadSettings(QString _filename){
if ( !QFile(_filename).exists() )
return;
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath);
if ( complete_name.endsWith("ini") ) {
openIniFile(complete_name);
if ( _filename.endsWith("ini") ) {
openIniFile(_filename);
applyOptions();
} else if ( complete_name.endsWith("obj") ) {
openObjFile(complete_name);
} else if ( _filename.endsWith("obj") ) {
openObjFile(_filename);
applyOptions();
}
if ( OpenFlipper::Options::gui() )
coreWidget_->addRecent(complete_name, DATA_NONE);
}
This diff is collapsed.
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// 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.
//
// 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 Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 3388 $
// $Author: wilden $
// $Date: 2008-10-15 11:26:18 +0200 (Wed, 15 Oct 2008) $
//
//=============================================================================
#include "Core.hh"
#include "OpenFlipper/common/GlobalOptions.hh"
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/widgets/loadWidget/loadWidget.hh"
#include <QFileDialog>
#include <QGroupBox>
#include <QBoxLayout>
/// Save Settings (slot is called from CoreWidget's File-Menu)
void Core::saveSettings(){
// generate the saveSettings-Dialog
QString complete_name;
QFileDialog fileDialog( coreWidget_,
tr("Save Settings"),
OpenFlipper::Options::currentDirStr(),
tr("INI files (*.ini);;OBJ files (*.obj )") );
fileDialog.setAcceptMode ( QFileDialog::AcceptSave );
fileDialog.setFileMode ( QFileDialog::AnyFile );
fileDialog.setDefaultSuffix("ini");
QGridLayout *layout = (QGridLayout*)fileDialog.layout();
QGroupBox* optionsBox = new QGroupBox( &fileDialog ) ;
optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
optionsBox->setTitle("Options");
layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
QCheckBox *saveAllBox = new QCheckBox(optionsBox);
saveAllBox->setText("Save everything to same folder");
saveAllBox->setToolTip("Save all open files to the same folder as the ini file");
saveAllBox->setCheckState( Qt::Checked );
QCheckBox *askOverwrite = new QCheckBox(optionsBox);
askOverwrite->setText("Ask before overwriting files");
askOverwrite->setToolTip("If a file exists you will get asked what to do");
askOverwrite->setCheckState( Qt::Checked );
QCheckBox *targetOnly = new QCheckBox(optionsBox);
targetOnly->setText("Save only target objects");
targetOnly->setToolTip("Only objects with target flag will be handled");
targetOnly->setCheckState( Qt::Unchecked );
QBoxLayout* frameLayout = new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
frameLayout->addWidget( saveAllBox , 0 , 0);
frameLayout->addWidget( askOverwrite , 1 , 0);
frameLayout->addWidget( targetOnly , 2 , 0);
frameLayout->addStretch();
// show the saveSettings-Dialog
QStringList fileNames;
if (fileDialog.exec()) {
fileNames = fileDialog.selectedFiles();
} else {
return;
}
if ( fileNames.size() > 1 ) {
std::cerr << "Too many save filenames selected" << std::endl;
return;
}
complete_name = fileNames[0];
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath);
//update status
OpenFlipper::Options::savingSettings(true);
if ( OpenFlipper::Options::gui() ) {
coreWidget_->statusMessage( "Saving Settings to " + complete_name + " ...");
coreWidget_->setStatus(ApplicationStatus::BLOCKED );
}
PluginFunctions::IteratorRestriction restriction;
if ( targetOnly->isChecked() )
restriction = PluginFunctions::TARGET_OBJECTS;
else
restriction = PluginFunctions::ALL_OBJECTS;
//iterate over opened objects and save them
for ( PluginFunctions::ObjectIterator o_it(restriction);
o_it != PluginFunctions::objects_end(); ++o_it)
{
QString filename;
if ( saveAllBox->isChecked() )
{
// Use path of settings file for all objects
filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
}
else
{
// Use objects own path if it has one. Otherwise also use path of settings file
filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
// filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
// handle the case that the object was created in current session and not loaded from disk
if (o_it->path() == ".") {
filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
std::cerr << "newpath : " << newpath.toStdString() << std::endl;
std::cerr << "name : " << o_it->name().toStdString() << std::endl;
}
}
// enforce that all files end with obj extension if its an obj-settings file
if ( complete_name.endsWith("obj") )
{
if (!filename.endsWith("obj"))
{
// remove old extension
int pos = filename.lastIndexOf(".");
filename.remove(pos+1, filename.length() - pos);
// add obj extension
filename += "obj";
}
}
// decide whether to use saveObject or saveObjectTo
if ( !QFile(filename).exists() || !askOverwrite->isChecked() )
saveObject( o_it->id(), filename);
else
saveObjectTo(o_it->id(), filename);
}
//finally save all Settings
if ( complete_name.endsWith("ini") ) {
//write to ini
writeIniFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked() );
} else if ( complete_name.endsWith("obj") ) {
//write to obj
writeObjFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked() );
}
//update status
OpenFlipper::Options::savingSettings(false);
if ( OpenFlipper::Options::gui() ) {
coreWidget_->statusMessage( "Saving Settings to " + complete_name + " ... Done", 4000);
coreWidget_->setStatus(ApplicationStatus::READY );
}
//add to recent files
if ( OpenFlipper::Options::gui() )
coreWidget_->addRecent( complete_name, DATA_NONE );
}
......@@ -163,8 +163,11 @@ static QString lastDataType_ = "Triangle Mesh";
/// Should backups be enabled
static bool enableBackup_ = true;
/// Currently opening an ini file?
static bool openingIni_ = false;
/// Currently loading Settings?
static bool loadingSettings_ = false;
/// Currently saving Settings?
static bool savingSettings_ = false;
static int* argc_;
......@@ -552,12 +555,20 @@ void enableBackup(bool _enableBackup ) {
enableBackup_ = _enableBackup;
}
bool openingIni( ) {
return openingIni_;
bool loadingSettings( ) {
return loadingSettings_;
}
void loadingSettings(bool _loadingSettings ) {
loadingSettings_ = _loadingSettings;
}
bool savingSettings( ) {
return savingSettings_;
}
void openingIni(bool _openingIni ) {
openingIni_ = _openingIni;
void savingSettings(bool _savingSettings ) {
savingSettings_ = _savingSettings;
}
int* argc() {
......
......@@ -514,18 +514,25 @@ bool iconDir(QString _dir);
/** @} */
//===========================================================================
/** @name INI operations
/** @name Settings
* @{ */
//===========================================================================
/// Do backups?
/// currently loading Settings ?
DLLEXPORT
bool openingIni( );
bool loadingSettings( );
/// Do backups?
/// currently loading Settings ?
DLLEXPORT
void openingIni(bool _openingIni );
void loadingSettings(bool _loadingSettings );
/// currently saving Settings ?
DLLEXPORT
bool savingSettings( );
/// currently saving Settings ?
DLLEXPORT
void savingSettings(bool _savingSettings );
/** @} */
......
......@@ -532,8 +532,8 @@ CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString
void
CoreWidget::addRecent(QString _filename, DataType _type)
{
//dont add objects within INI files to recentMenu
if ( OpenFlipper::Options::openingIni() ) return;
//dont add objects to recentMenu while loadind Settings
if ( OpenFlipper::Options::loadingSettings() ) return;
OpenFlipper::Options::addRecentFile(_filename, _type);
......
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