Commit 1dbf9bef authored by Jan Möbius's avatar Jan Möbius
Browse files

Added TypeSphere Plugin

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9069 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 344b1416
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: moebius $ *
* $Date: 2010-02-12 14:30:50 +0100 (Fr, 12. Feb 2010) $ *
* *
\*===========================================================================*/
#include <QtGui>
#include <QFileInfo>
#include <QSettings>
#include "FileSPH.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 FileSPHPlugin::initializePlugin() {
}
QString FileSPHPlugin::getLoadFilters() {
return QString( tr("Sphere definition files ( *.sph )") );
};
QString FileSPHPlugin::getSaveFilters() {
return QString( tr("Sphere definition files ( *.sph )") );
};
DataType FileSPHPlugin::supportedType() {
DataType type = DATA_SPHERE;
return type;
}
int FileSPHPlugin::loadObject(QString _filename)
{
int id = -1;
emit addEmptyObject( DATA_SPHERE, id );
SphereObject* sphereObject = 0;
if(PluginFunctions::getObject( id, sphereObject))
{
if( sphereObject )
{
QFileInfo fi(_filename);
if ( fi.exists() ){
SphereNode* sphere = PluginFunctions::sphereNode(sphereObject);
QString name = sphereObject->name();
QSettings settings(_filename, QSettings::IniFormat);
settings.beginGroup("SPHERE");
if ( settings.contains("Name") ) {
QString name = settings.value("Name").toString();
sphereObject->setName( name );
} else {
sphereObject->setFromFileName(_filename);
}
ACG::Vec3d position;
double size;
int slices,stacks;
if ( settings.contains("PositionX") ) {
position[0] = settings.value("PositionX").toDouble();
position[1] = settings.value("PositionY").toDouble();
position[2] = settings.value("PositionZ").toDouble();
sphere->get_primitive(0).position = position;
}
if ( settings.contains("Size") ){
size = settings.value("Size").toDouble();
sphere->get_primitive(0).size = size;
}
if ( settings.contains("Slices") ){
slices = settings.value("Slices").toDouble();
sphere->get_primitive(0).slices = slices;
}
if ( settings.contains("Stacks") ){
stacks = settings.value("Stacks").toDouble();
sphere->get_primitive(0).stacks = stacks;
}
settings.endGroup();
}
}
emit updatedObject( sphereObject->id(), UPDATE_ALL );
emit openedFile( sphereObject->id() );
}
return id;
};
bool FileSPHPlugin::saveObject(int _id, QString _filename)
{
BaseObjectData* obj(0);
if(PluginFunctions::getObject( _id, obj))
{
SphereObject* sphereObject = PluginFunctions::sphereObject(obj);
if( sphereObject )
{
SphereNode* sphere = PluginFunctions::sphereNode(sphereObject);
QSettings settings(_filename, QSettings::IniFormat);
settings.beginGroup("SPHERE");
settings.setValue("Name",sphereObject->name());
settings.setValue("PositionX", sphere->get_primitive(0).position[0]);
settings.setValue("PositionY", sphere->get_primitive(0).position[1]);
settings.setValue("PositionZ", sphere->get_primitive(0).position[2]);
settings.setValue("Size", sphere->get_primitive(0).size);
settings.setValue("Slices", sphere->get_primitive(0).slices);
settings.setValue("Stacks", sphere->get_primitive(0).stacks);
settings.endGroup();
obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(),-1));
obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(),0,-2) );
}
}
return true;
}
QString FileSPHPlugin::get_unique_name(SphereObject* _object)
{
bool name_unique = false;
int cur_idx = _object->id();
while(!name_unique)
{
name_unique = true;
QString cur_name = QString(tr("Sphere %1.sph").arg( cur_idx ));
PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS, DATA_SPHERE );
for(; o_it != PluginFunctions::objectsEnd(); ++o_it)
{
if( o_it->name() == cur_name)
{
name_unique = false;
cur_idx += 10;
break;
}
}
}
return QString(tr("Sphere %1.sph").arg( cur_idx ));
}
Q_EXPORT_PLUGIN2( filesphplugin , FileSPHPlugin );
/*===========================================================================*\
* *
* 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) $ *
* *
\*===========================================================================*/
#ifndef FILESPHPLUGIN_HH
#define FILESPHPLUGIN_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>
#include <ObjectTypes/Sphere/Sphere.hh>
class FileSPHPlugin : 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 updatedObject(int _id, const UpdateType _type);
private slots:
void fileOpened( int /*_id*/ ){};
void noguiSupported( ) {} ;
void initializePlugin();
// Deprecated!
int addEmpty() { return -1; };
public :
~FileSPHPlugin() {};
QString name() { return (QString("FileSPH")); };
QString description( ) { return (QString(tr("Load/Save Spheres"))); };
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 addNewSphere();
QString version() { return QString("1.0"); };
private :
QString get_unique_name(SphereObject* _object);
};
#endif //FILESPHPLUGIN_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 "FileSPH.hh"
int FileSPHPlugin::addNewSphere() {
return addEmpty();
}
......@@ -53,6 +53,38 @@
INIPlugin::INIPlugin() {
}
template <>
void INIPlugin::parseIniFileT(INIFile& _ini, LightObject* _object) {
if ( _object ) {
std::vector< QString > draw_modes;
if( _ini.get_entry(draw_modes, _object->name(), "MaterialDrawMode") )
_object->materialNode()->drawMode( listToDrawMode(draw_modes) );
bool visible;
if ( _ini.get_entry( visible, _object->name() , "Visible" ) ) {
_object->visible(visible);
std::cerr << "visible" << std::endl;
}
}
}
template <>
void INIPlugin::saveIniFileT(INIFile& _ini, LightObject* _object) {
if ( _object ) {
_ini.add_entry( _object->name() ,
"MaterialDrawMode" ,
drawModeToList( _object->materialNode()->drawMode()) );
_ini.add_entry( _object->name() ,
"Visible" ,
_object->visible() );
}
}
void INIPlugin::loadIniFile( INIFile& _ini, int _id ) {
BaseObjectData* baseObject;
......@@ -62,7 +94,8 @@ void INIPlugin::loadIniFile( INIFile& _ini, int _id ) {
}
PolyMeshObject* polyObject(0);
TriMeshObject* triObject(0);
TriMeshObject* triObject(0);
LightObject* lightObject(0);
if(baseObject->dataType() == DATA_POLY_MESH) {
polyObject = PluginFunctions::polyMeshObject(baseObject);
......@@ -71,7 +104,8 @@ void INIPlugin::loadIniFile( INIFile& _ini, int _id ) {
triObject = PluginFunctions::triMeshObject(baseObject);
parseIniFileT(_ini, triObject);
} else if ( baseObject->dataType() == DATA_LIGHT ) {
// No special Information needed yet
lightObject = PluginFunctions::lightObject(baseObject);
parseIniFileT(_ini, lightObject);
} else {
// Unhandled data type
emit log(LOGERR, tr("The specified data type is not supported, yet. Aborting!"));
......@@ -87,7 +121,8 @@ void INIPlugin::saveIniFile( INIFile& _ini, int _id) {
}
PolyMeshObject* polyObject(0);
TriMeshObject* triObject(0);
TriMeshObject* triObject(0);
LightObject* lightObject(0);
if(baseObject->dataType() == DATA_POLY_MESH) {
polyObject = PluginFunctions::polyMeshObject(baseObject);
......@@ -95,10 +130,15 @@ void INIPlugin::saveIniFile( INIFile& _ini, int _id) {
} else if ( baseObject->dataType() == DATA_TRIANGLE_MESH) {
triObject = PluginFunctions::triMeshObject(baseObject);
saveIniFileT(_ini, triObject);
} else if ( baseObject->dataType() == DATA_LIGHT ) {
lightObject = PluginFunctions::lightObject(baseObject);
saveIniFileT(_ini, lightObject);
} else {
// Unhandled data type
emit log(LOGERR, tr("The specified data type is not supported, yet. Aborting!"));
// Unhandled data type
emit log(LOGERR, tr("The specified data type is not supported, yet. Aborting!"));
}
}
Q_EXPORT_PLUGIN2( iniplugin , INIPlugin );
\ No newline at end of file
......@@ -83,12 +83,12 @@ class INIPlugin : public QObject, BaseInterface, LoggingInterface, ScriptInterfa
private:
// Template function to parse ini file entries
template <class MeshObject>
void parseIniFileT(INIFile& _ini, MeshObject* _object);
template <class Object>
void parseIniFileT(INIFile& _ini, Object* _object);
// Template function to save ini file entries
template <class MeshObject>
void saveIniFileT(INIFile& _ini, MeshObject* _object);
template <class Object>
void saveIniFileT(INIFile& _ini, Object* _object);
};
//=============================================================================
......
#include "iniPlugin.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
#include <ObjectTypes/MeshObject/MeshObjectT.hh>
#include <OpenFlipper/common/BaseObjectData.hh>
template <class MeshObject>
void INIPlugin::parseIniFileT(INIFile& _ini, MeshObject* _object) {
......@@ -37,6 +40,11 @@ void INIPlugin::parseIniFileT(INIFile& _ini, MeshObject* _object) {
_object->materialNode()->set_reflectance(reflectance);
}
bool visible;
if ( _ini.get_entry( visible, _object->name() , "Visible" ) ) {
_object->visible(visible);
}
int size = 1;
if ( _ini.get_entry( size, _object->name() , "PointSize" ) )
_object->materialNode()->set_point_size(size);
......@@ -72,7 +80,10 @@ void INIPlugin::saveIniFileT(INIFile& _ini, MeshObject* _object) {
_object->materialNode()->shininess());
_ini.add_entry( _object->name() ,
"Reflectance" ,
_object->materialNode()->reflectance());
_object->materialNode()->reflectance());
_ini.add_entry( _object->name() ,
"Visible" ,
_object->visible() );
_ini.add_entry( _object->name() ,
"PointSize" ,
_object->materialNode()->point_size());
......@@ -81,3 +92,4 @@ void INIPlugin::saveIniFileT(INIFile& _ini, MeshObject* _object) {
_object->materialNode()->line_width());
}
}
......@@ -45,9 +45,9 @@
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#define DEF0 "Default Light 0"
#define DEF1 "Default Light 1"
#define DEF2 "Default Light 2"
#define DEF0 "Default Light 0.lgt"
#define DEF1 "Default Light 1.lgt"
#define DEF2 "Default Light 2.lgt"
TypeLightPlugin::TypeLightPlugin() :
defaultLights_(true) {
......
/*===========================================================================*\
* *
* 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: 6753 $ *
* $Author: moebius $ *
* $Date: 2009-08-05 12:38:20 +0200 (Mi, 05. Aug 2009) $ *
* *
\*===========================================================================*/
#include "TypeSphere.hh"
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
TypeSpherePlugin::TypeSpherePlugin() {
}
bool TypeSpherePlugin::registerType() {
addDataType("Sphere",tr("Sphere"));
// setTypeIcon( "Sphere", "SphereType.png");
return true;
}
int TypeSpherePlugin::addEmpty(){
// new object data struct
SphereObject * object = new SphereObject();
if ( PluginFunctions::objectCount() == 1 )
object->target(true);
if (PluginFunctions::targetCount() == 0 )
object->target(true);
QString name = get_unique_name(object);
// call the local function to update names
QFileInfo f(name);