Commit e2168487 authored by Mike Kremer's avatar Mike Kremer

Added file plugin for ofv-files that contain view settings.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9013 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3b22a4c4
include (plugin)
openflipper_plugin ()
/*===========================================================================*\
* *
* 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/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 8545 $ *
* $Author: kremer $ *
* $Date: 2010-02-12 14:30:50 +0100 (Fr, 12. Feb 2010) $ *
* *
\*===========================================================================*/
#include <QtGui>
#include <QFileInfo>
#include <QSettings>
#include "FileOfv.hh"
#include <iostream>
#include <ACG/GL/GLState.hh>
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/common/GlobalOptions.hh"
#include <OpenMesh/Core/IO/IOManager.hh>
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
void FileViewPlugin::initializePlugin() {
}
QString FileViewPlugin::getLoadFilters() {
return QString( tr("View definition files ( *.ofv )") );
};
QString FileViewPlugin::getSaveFilters() {
return QString( tr("View definition files ( *.ofv )") );
};
DataType FileViewPlugin::supportedType() {
return DataType();
}
int FileViewPlugin::loadObject(QString _filename) {
// Declare variables
int width = 1;
int height = 1;
ACG::Vec3d eye;
ACG::Vec3d center;
ACG::Vec3d up;
float fovy = 0;
ACG::Vec4f background;
bool e_widthAndHeight = false;
bool e_eye = false;
bool e_center = false;
bool e_up = false;
bool e_fovy = false;
bool e_background = false;
QSettings settings(_filename, QSettings::IniFormat);
settings.beginGroup("VIEW");
if(settings.contains("Width") && settings.contains("Height")) {
width = settings.value("Width").toInt();
height = settings.value("Height").toInt();
std::cerr << "Setting new viewport to " << width << "x" << height << std::endl;
e_widthAndHeight = true;
}
if(settings.contains("EyeX")) {
eye[0] = settings.value("EyeX").toDouble();
eye[1] = settings.value("EyeY").toDouble();
eye[2] = settings.value("EyeZ").toDouble();
std::cerr << "Setting new eye position to " << eye << std::endl;
e_eye = true;
}
if(settings.contains("CenterX")) {
center[0] = settings.value("CenterX").toDouble();
center[1] = settings.value("CenterY").toDouble();
center[2] = settings.value("CenterZ").toDouble();
std::cerr << "Setting new scene center to " << center << std::endl;
e_center = true;
}
if(settings.contains("UpX")) {
up[0] = settings.value("UpX").toDouble();
up[1] = settings.value("UpY").toDouble();
up[2] = settings.value("UpZ").toDouble();
std::cerr << "Setting new up vector to " << up << std::endl;
e_up = true;
}
if(settings.contains("Fovy")) {
fovy = settings.value("Fovy").toDouble();
std::cerr << "Setting fovy to " << fovy << std::endl;
e_fovy = true;
}
if(settings.contains("BackgroundR")) {
background[0] = settings.value("BackgroundR").toDouble();
background[1] = settings.value("BackgroundG").toDouble();
background[2] = settings.value("BackgroundB").toDouble();
background[3] = settings.value("BackgroundA").toDouble();
std::cerr << "Setting new background color to " << background << std::endl;
e_background = true;
}
settings.endGroup();
// Now set new projection and view
ACG::Vec3d new_up;
// Get number of viewers
int viewers = PluginFunctions::viewers();
for(int i = 0; i < viewers; ++i) {
Viewer::ViewerProperties& props = PluginFunctions::viewerProperties(i);
ACG::GLState& state = props.glState();
// Perspective update
double aspect = 0.0;
if(e_widthAndHeight) aspect = width / height;
else aspect = state.aspect();
double near = state.near_plane();
double far = state.far_plane();
new_up = e_up ? up : state.up();
// Set projection matrix
//if(e_fovy)
// state.perspective(fovy, aspect, near, far);
// Viewport
//if(e_widthAndHeight)
// state.viewport(0, 0, width, height);
//std::cerr << "Fovy: " << state.fovy() << std::endl;
}
// LookAt
ACG::Vec3d new_eye = e_eye ? eye : PluginFunctions::eyePos();
ACG::Vec3d new_center = e_center ? center : PluginFunctions::sceneCenter();
PluginFunctions::lookAt(new_eye, new_center, new_up);
// Background color
if(e_background) {
PluginFunctions::setBackColor(background);
}
emit updateView();
return 0;
};
bool FileViewPlugin::saveObject(int /*_id*/, QString /*_filename*/) {
return true;
}
Q_EXPORT_PLUGIN2( fileviewplugin , FileViewPlugin );
/*===========================================================================*\
* *
* 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/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 7920 $ *
* $Author: kremer $ *
* $Date: 2009-12-15 10:07:03 +0100 (Di, 15. Dez 2009) $ *
* *
\*===========================================================================*/
#ifndef FILEVIEWPLUGIN_HH
#define FILEVIEWPLUGIN_HH
#include <QObject>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/FileInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/INIInterface.hh>
class FileViewPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface, LoggingInterface, ScriptInterface, INIInterface
{
Q_OBJECT
Q_INTERFACES(FileInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ScriptInterface)
Q_INTERFACES(INIInterface)
signals:
void openedFile( int _id );
void addEmptyObject( DataType _type, int& _id);
void load(QString _filename, DataType _type, int& _id);
void save(int _id , QString _filename );
void log(Logtype _type, QString _message);
void log(QString _message);
void emptyObjectAdded( int _id );
void updateView();
private slots:
void fileOpened( int /*_id*/ ){};
void noguiSupported( ) {} ;
void initializePlugin();
// Deprecated!
int addEmpty() { return -1; };
public :
~FileViewPlugin() {};
QString name() { return (QString("FileView")); };
QString description( ) { return (QString(tr("Load/Save Views"))); };
DataType supportedType();
QString getSaveFilters();
QString getLoadFilters();
QWidget* saveOptionsWidget(QString /*_currentFilter*/) { return 0; };
QWidget* loadOptionsWidget(QString /*_currentFilter*/) { return 0; };
public slots:
int loadObject(QString _filename);
bool saveObject(int _id, QString _filename);
int addNewLight();
QString version() { return QString("1.0"); };
};
#endif //FILEVIEWPLUGIN_HH
/*===========================================================================*\
* *
* 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/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 7920 $ *
* $Author: moebius $ *
* $Date: 2009-12-15 10:07:03 +0100 (Di, 15. Dez 2009) $ *
* *
\*===========================================================================*/
#include "FileOfv.hh"
int FileViewPlugin::addNewLight() {
return addEmpty();
}
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