Commit 7ff3e5f0 authored by Jan Möbius's avatar Jan Möbius

Updated internal types handling (directly initialized by core now)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7697 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3eb89e36
...@@ -181,6 +181,9 @@ Core() : ...@@ -181,6 +181,9 @@ Core() :
// set discriptions for scriptable slots // set discriptions for scriptable slots
setDescriptions(); setDescriptions();
// Initialize the build in dataTypes
initializeTypes();
} }
/** \brief Second initialization stage /** \brief Second initialization stage
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
//== INCLUDES ================================================================= //== INCLUDES =================================================================
#include "OpenFlipper/common/Types.hh" #include "OpenFlipper/common/TypesInternal.hh"
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh> #include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
......
...@@ -84,6 +84,7 @@ void Core::resetScenegraph( bool _resetTrackBall ) { ...@@ -84,6 +84,7 @@ void Core::resetScenegraph( bool _resetTrackBall ) {
void Core::slotGetAllFilters ( QStringList& _list){ void Core::slotGetAllFilters ( QStringList& _list){
/// \todo check why the supported Type is used here!
// Iterate over all types // Iterate over all types
for (int i=0; i < (int)supportedTypes_.size(); i++){ for (int i=0; i < (int)supportedTypes_.size(); i++){
QString f = supportedTypes_[i].plugin->getLoadFilters(); QString f = supportedTypes_[i].plugin->getLoadFilters();
...@@ -243,10 +244,10 @@ int Core::loadObject( DataType _type, QString _filename) { ...@@ -243,10 +244,10 @@ int Core::loadObject( DataType _type, QString _filename) {
int Core::addEmptyObject( DataType _type ) { int Core::addEmptyObject( DataType _type ) {
/** \todo Iterate over all plugins but check with bitmask! for a supporting plugin // Iterate over all plugins. The first plugin supporting the addEmpty function for the
*/ // specified type will be used to create the new object.
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 )
return supportedTypes_[i].plugin->addEmpty(); return supportedTypes_[i].plugin->addEmpty();
return -1; //no plugin found return -1; //no plugin found
} }
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include "Types.hh" #include "Types.hh"
#include <map> #include <map>
#include <QCoreApplication> #include <QCoreApplication>
#include <OpenFlipper/common/GlobalOptions.hh>
/** This field defines the start id for custom datatypes. It starts high to avoid conflicts with previously /** This field defines the start id for custom datatypes. It starts high to avoid conflicts with previously
...@@ -67,9 +68,6 @@ ...@@ -67,9 +68,6 @@
*/ */
static int nextTypeId_ = 8; static int nextTypeId_ = 8;
/// Variable used to automatically initialize the maps
static bool initialized_ = false;
/** This map maps an dataType id to an typeName /** This map maps an dataType id to an typeName
*/ */
static std::map< unsigned int, QString > typeToString; static std::map< unsigned int, QString > typeToString;
...@@ -106,16 +104,19 @@ class TypeInfo { ...@@ -106,16 +104,19 @@ class TypeInfo {
/// The icon of the datatype /// The icon of the datatype
QString iconName; QString iconName;
QIcon icon;
/// Human readable name /// Human readable name
QString readableName; QString readableName;
}; };
static QIcon dummyIcon;
static std::vector< TypeInfo > types; static std::vector< TypeInfo > types;
//== Functions ========================================================= //== Functions =========================================================
void initialize() { void initializeTypes() {
if ( !initialized_ ) {
stringToTypeInfo["Unknown"] = types.size(); stringToTypeInfo["Unknown"] = types.size();
typeToTypeInfo[DATA_UNKNOWN] = types.size(); typeToTypeInfo[DATA_UNKNOWN] = types.size();
types.push_back( TypeInfo(DATA_UNKNOWN ,"Unknown" ,"Unknown.png", QCoreApplication::translate("Types","Unknown")) ); types.push_back( TypeInfo(DATA_UNKNOWN ,"Unknown" ,"Unknown.png", QCoreApplication::translate("Types","Unknown")) );
...@@ -142,13 +143,14 @@ void initialize() { ...@@ -142,13 +143,14 @@ void initialize() {
typeToString[DATA_POLY_MESH_CONST_ID] = "PolyMesh"; typeToString[DATA_POLY_MESH_CONST_ID] = "PolyMesh";
typeToString[DATA_ALL] = "All"; typeToString[DATA_ALL] = "All";
initialized_ = true; // Preload the static icons
} setTypeIcon(DATA_TRIANGLE_MESH_CONST_ID,"TriangleType.png");
setTypeIcon(DATA_POLY_MESH_CONST_ID,"PolyType.png");
} }
/// Adds a datatype and returns the id for the new type /// Adds a datatype and returns the id for the new type
DataType addDataType(QString _name, QString _readableName) { DataType addDataType(QString _name, QString _readableName) {
initialize();
int type = nextTypeId_; int type = nextTypeId_;
...@@ -164,7 +166,6 @@ DataType addDataType(QString _name, QString _readableName) { ...@@ -164,7 +166,6 @@ DataType addDataType(QString _name, QString _readableName) {
/// Get the id of a type with given name /// Get the id of a type with given name
DataType typeId(QString _name) { DataType typeId(QString _name) {
initialize();
std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _name ); std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _name );
...@@ -180,26 +181,27 @@ DataType typeId(QString _name) { ...@@ -180,26 +181,27 @@ DataType typeId(QString _name) {
/// Get the name of a type with given id /// Get the name of a type with given id
QString typeName(DataType _id) { QString typeName(DataType _id) {
initialize();
std::map<unsigned int, QString>::iterator name = typeToString.find(_id); std::map<unsigned int, QString>::iterator name = typeToString.find(_id);
if ( name != typeToString.end() ) if ( name != typeToString.end() )
return name->second; return name->second;
else { else {
#ifdef DEBUG
std::cerr << "Unable to retrieve typeName for id " << _id << std::endl; std::cerr << "Unable to retrieve typeName for id " << _id << std::endl;
#endif
return "Unknown"; return "Unknown";
} }
} }
/// Return the number of registered types /// Return the number of registered types
uint typeCount() { uint typeCount() {
return types.size(); return types.size();
} }
/// Get the icon of a given dataType /// Get the icon of a given dataType
QString typeIcon(QString _name) { QString typeIconName(QString _name) {
initialize();
std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _name ); std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _name );
...@@ -210,8 +212,7 @@ QString typeIcon(QString _name) { ...@@ -210,8 +212,7 @@ QString typeIcon(QString _name) {
} }
/// get the icon of a given dataType /// get the icon of a given dataType
QString typeIcon(DataType _id) { QString typeIconName(DataType _id) {
initialize();
std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id); std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id);
...@@ -221,27 +222,38 @@ QString typeIcon(DataType _id) { ...@@ -221,27 +222,38 @@ QString typeIcon(DataType _id) {
return "Unknown.png"; return "Unknown.png";
} }
/// get the icon of a given dataType
QIcon& typeIcon(DataType _id) {
std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id);
if ( index != typeToTypeInfo.end() )
return types[ index->second ].icon;
else
return dummyIcon;
}
/// Set the icon for a given dataType /// Set the icon for a given dataType
void setTypeIcon( DataType _id , QString _icon ) { void setTypeIcon( DataType _id , QString _icon ) {
initialize();
std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id); std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id);
if ( index != typeToTypeInfo.end() ) if ( index != typeToTypeInfo.end() ) {
types[ index->second ].iconName = _icon; types[ index->second ].iconName = _icon;
else types[ index->second ].icon = QIcon( OpenFlipper::Options::iconDirStr() + QDir::separator() + _icon );
} else
std::cerr << "Could not set icon for DataType. Type not found!" << std::endl; std::cerr << "Could not set icon for DataType. Type not found!" << std::endl;
} }
/// Set the icon for a given dataType /// Set the icon for a given dataType
void setTypeIcon( QString _name , QString _icon ) { void setTypeIcon( QString _name , QString _icon ) {
initialize();
std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _name ); std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _name );
if ( index != stringToTypeInfo.end() ) if ( index != stringToTypeInfo.end() ) {
types[ index->second ].iconName = _icon; types[ index->second ].iconName = _icon;
else types[ index->second ].icon = QIcon( OpenFlipper::Options::iconDirStr() + QDir::separator() + _icon );
} else
std::cerr << "Could not set icon for DataType. Type not found!" << std::endl; std::cerr << "Could not set icon for DataType. Type not found!" << std::endl;
} }
...@@ -250,7 +262,6 @@ void setTypeIcon( QString _name , QString _icon ) { ...@@ -250,7 +262,6 @@ void setTypeIcon( QString _name , QString _icon ) {
/// Get DataType Human readable name ( this name might change. Use the typeName insted! ) /// Get DataType Human readable name ( this name might change. Use the typeName insted! )
QString dataTypeName( DataType _id ) { QString dataTypeName( DataType _id ) {
initialize();
std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id); std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id);
...@@ -264,7 +275,6 @@ QString dataTypeName( DataType _id ) { ...@@ -264,7 +275,6 @@ QString dataTypeName( DataType _id ) {
/// Get DataType Human readable name ( this name might change. Use the typeName insted! ) /// Get DataType Human readable name ( this name might change. Use the typeName insted! )
QString dataTypeName( QString _typeName ) { QString dataTypeName( QString _typeName ) {
initialize();
std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _typeName ); std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _typeName );
...@@ -280,7 +290,6 @@ QString dataTypeName( QString _typeName ) { ...@@ -280,7 +290,6 @@ QString dataTypeName( QString _typeName ) {
/// Set the icon for a given dataType /// Set the icon for a given dataType
void setDataTypeName( DataType _id , QString _name ) { void setDataTypeName( DataType _id , QString _name ) {
initialize();
std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id); std::map<unsigned int, unsigned int>::iterator index = typeToTypeInfo.find(_id);
...@@ -292,7 +301,6 @@ void setDataTypeName( DataType _id , QString _name ) { ...@@ -292,7 +301,6 @@ void setDataTypeName( DataType _id , QString _name ) {
/// Set the icon for a given dataType /// Set the icon for a given dataType
void setDataTypeName( QString _typeName , QString _name ) { void setDataTypeName( QString _typeName , QString _name ) {
initialize();
std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _typeName ); std::map<QString, unsigned int>::iterator index = stringToTypeInfo.find( _typeName );
......
...@@ -181,13 +181,21 @@ void setDataTypeName( QString _typeName, QString _name ); ...@@ -181,13 +181,21 @@ void setDataTypeName( QString _typeName, QString _name );
* @{ */ * @{ */
//================================================================================================ //================================================================================================
/// Get an icon for a given DataType /// Get a string with the filename of the icon for the DataType name
DLLEXPORT DLLEXPORT
QString typeIcon(QString _name); QString typeIconName(QString _name);
/// Get an icon for a given DataType /// Get a string with the filename of the icon for the DataType
DLLEXPORT DLLEXPORT
QString typeIcon(DataType _id); QString typeIconName(DataType _id);
/** \brief Get an QIcon associated with the given datatype
*
* The icons are loaded once when set and then the reference is returned here.
* This reduces the time when frequently requesting the icons (e.g. DataControl)
*/
DLLEXPORT
QIcon& typeIcon(DataType _id);
/// Set an Icon for a given DataType /// Set an Icon for a given DataType
DLLEXPORT DLLEXPORT
......
/*===========================================================================*\
* *
* 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: 7673 $ *
* $Author: moebius $ *
* $Date: 2009-11-30 12:45:38 +0100 (Mo, 30. Nov 2009) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// Types
//
//=============================================================================
/**
* \file TypesInternal.hh
* This File contains the functions for internal communication between types and
* the core. Do not use in Plugins!!!
*/
#ifndef TYPESINTERNAL_HH
#define TYPESINTERNAL_HH
//== INCLUDES =================================================================
#include <OpenFlipper/common/Types.hh>
void initializeTypes();
//=============================================================================
#endif // TYPESINTERNAL_HH defined
//=============================================================================
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