diff --git a/Core/Core.cc b/Core/Core.cc index 1ec217ac055659bc69ec031b92f037505b4bdbed..e1dadb9c5b340c7df3e5c31f80531490f8f8f088 100644 --- a/Core/Core.cc +++ b/Core/Core.cc @@ -181,6 +181,9 @@ Core() : // set discriptions for scriptable slots setDescriptions(); + + // Initialize the build in dataTypes + initializeTypes(); } /** \brief Second initialization stage diff --git a/Core/Core.hh b/Core/Core.hh index c689fd099b97aa199ec0c882220aa02665ce6ada..0a212769c56a8db0b408ee9e94848e711eff46c1 100644 --- a/Core/Core.hh +++ b/Core/Core.hh @@ -61,7 +61,7 @@ //== INCLUDES ================================================================= -#include "OpenFlipper/common/Types.hh" +#include "OpenFlipper/common/TypesInternal.hh" #include diff --git a/Core/openFunctions.cc b/Core/openFunctions.cc index 2b292ec780af042bd73979d0324a75db655ea3b3..54c2dd0b82a93939da139bdd38f48b6e9aafe9d1 100644 --- a/Core/openFunctions.cc +++ b/Core/openFunctions.cc @@ -84,6 +84,7 @@ void Core::resetScenegraph( bool _resetTrackBall ) { void Core::slotGetAllFilters ( QStringList& _list){ + /// \todo check why the supported Type is used here! // Iterate over all types for (int i=0; i < (int)supportedTypes_.size(); i++){ QString f = supportedTypes_[i].plugin->getLoadFilters(); @@ -243,10 +244,10 @@ int Core::loadObject( DataType _type, QString _filename) { 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++) - if (supportedTypes_[i].type == _type) + if ( supportedTypes_[i].type & _type ) return supportedTypes_[i].plugin->addEmpty(); return -1; //no plugin found } diff --git a/common/Types.cc b/common/Types.cc index 5c08da1964f91bfe897f7a6586a48e748e4d141e..c09c3e41b19f6b363fcc40a00481f68998df7961 100644 --- a/common/Types.cc +++ b/common/Types.cc @@ -60,6 +60,7 @@ #include "Types.hh" #include #include +#include /** This field defines the start id for custom datatypes. It starts high to avoid conflicts with previously @@ -67,9 +68,6 @@ */ static int nextTypeId_ = 8; -/// Variable used to automatically initialize the maps -static bool initialized_ = false; - /** This map maps an dataType id to an typeName */ static std::map< unsigned int, QString > typeToString; @@ -105,51 +103,55 @@ class TypeInfo { /// The icon of the datatype QString iconName; + + QIcon icon; /// Human readable name QString readableName; }; +static QIcon dummyIcon; + static std::vector< TypeInfo > types; //== Functions ========================================================= -void initialize() { - if ( !initialized_ ) { - stringToTypeInfo["Unknown"] = types.size(); - typeToTypeInfo[DATA_UNKNOWN] = types.size(); - types.push_back( TypeInfo(DATA_UNKNOWN ,"Unknown" ,"Unknown.png", QCoreApplication::translate("Types","Unknown")) ); - - stringToTypeInfo["Group"] = types.size(); - typeToTypeInfo[DATA_GROUP] = types.size(); - types.push_back( TypeInfo(DATA_GROUP ,"Group" ,"Unknown.png", QCoreApplication::translate("Types","Group")) ); - - stringToTypeInfo["TriangleMesh"] = types.size(); - typeToTypeInfo[DATA_TRIANGLE_MESH_CONST_ID] = types.size(); - types.push_back( TypeInfo(DATA_TRIANGLE_MESH_CONST_ID ,"TriangleMesh" ,"TriangleType.png", QCoreApplication::translate("Types","Triangle Mesh")) ); - - stringToTypeInfo["PolyMesh"] = types.size(); - typeToTypeInfo[DATA_POLY_MESH_CONST_ID] = types.size(); - types.push_back( TypeInfo(DATA_POLY_MESH_CONST_ID ,"PolyMesh" ,"PolyType.png", QCoreApplication::translate("Types","Poly Mesh")) ); - - stringToTypeInfo["All"] = types.size(); - typeToTypeInfo[DATA_ALL] = types.size(); - types.push_back( TypeInfo(DATA_ALL ,"All" ,"Unknown.png", QCoreApplication::translate("Types","All")) ); +void initializeTypes() { + stringToTypeInfo["Unknown"] = types.size(); + typeToTypeInfo[DATA_UNKNOWN] = types.size(); + types.push_back( TypeInfo(DATA_UNKNOWN ,"Unknown" ,"Unknown.png", QCoreApplication::translate("Types","Unknown")) ); + + stringToTypeInfo["Group"] = types.size(); + typeToTypeInfo[DATA_GROUP] = types.size(); + types.push_back( TypeInfo(DATA_GROUP ,"Group" ,"Unknown.png", QCoreApplication::translate("Types","Group")) ); + + stringToTypeInfo["TriangleMesh"] = types.size(); + typeToTypeInfo[DATA_TRIANGLE_MESH_CONST_ID] = types.size(); + types.push_back( TypeInfo(DATA_TRIANGLE_MESH_CONST_ID ,"TriangleMesh" ,"TriangleType.png", QCoreApplication::translate("Types","Triangle Mesh")) ); + + stringToTypeInfo["PolyMesh"] = types.size(); + typeToTypeInfo[DATA_POLY_MESH_CONST_ID] = types.size(); + types.push_back( TypeInfo(DATA_POLY_MESH_CONST_ID ,"PolyMesh" ,"PolyType.png", QCoreApplication::translate("Types","Poly Mesh")) ); + + stringToTypeInfo["All"] = types.size(); + typeToTypeInfo[DATA_ALL] = types.size(); + types.push_back( TypeInfo(DATA_ALL ,"All" ,"Unknown.png", QCoreApplication::translate("Types","All")) ); + + typeToString[DATA_UNKNOWN] = "Unknown"; + typeToString[DATA_GROUP] = "Group"; + typeToString[DATA_TRIANGLE_MESH_CONST_ID] = "TriangleMesh"; + typeToString[DATA_POLY_MESH_CONST_ID] = "PolyMesh"; + typeToString[DATA_ALL] = "All"; + + // Preload the static icons + setTypeIcon(DATA_TRIANGLE_MESH_CONST_ID,"TriangleType.png"); + setTypeIcon(DATA_POLY_MESH_CONST_ID,"PolyType.png"); - typeToString[DATA_UNKNOWN] = "Unknown"; - typeToString[DATA_GROUP] = "Group"; - typeToString[DATA_TRIANGLE_MESH_CONST_ID] = "TriangleMesh"; - typeToString[DATA_POLY_MESH_CONST_ID] = "PolyMesh"; - typeToString[DATA_ALL] = "All"; - - initialized_ = true; - } } /// Adds a datatype and returns the id for the new type DataType addDataType(QString _name, QString _readableName) { - initialize(); - + int type = nextTypeId_; stringToTypeInfo[ _name ] = types.size(); @@ -164,7 +166,6 @@ DataType addDataType(QString _name, QString _readableName) { /// Get the id of a type with given name DataType typeId(QString _name) { - initialize(); std::map::iterator index = stringToTypeInfo.find( _name ); @@ -180,26 +181,27 @@ DataType typeId(QString _name) { /// Get the name of a type with given id QString typeName(DataType _id) { - initialize(); std::map::iterator name = typeToString.find(_id); if ( name != typeToString.end() ) return name->second; else { + #ifdef DEBUG std::cerr << "Unable to retrieve typeName for id " << _id << std::endl; + #endif return "Unknown"; } } + /// Return the number of registered types uint typeCount() { return types.size(); } /// Get the icon of a given dataType -QString typeIcon(QString _name) { - initialize(); +QString typeIconName(QString _name) { std::map::iterator index = stringToTypeInfo.find( _name ); @@ -210,8 +212,7 @@ QString typeIcon(QString _name) { } /// get the icon of a given dataType -QString typeIcon(DataType _id) { - initialize(); +QString typeIconName(DataType _id) { std::map::iterator index = typeToTypeInfo.find(_id); @@ -221,27 +222,38 @@ QString typeIcon(DataType _id) { return "Unknown.png"; } +/// get the icon of a given dataType +QIcon& typeIcon(DataType _id) { + + std::map::iterator index = typeToTypeInfo.find(_id); + + if ( index != typeToTypeInfo.end() ) + return types[ index->second ].icon; + else + return dummyIcon; +} + /// Set the icon for a given dataType void setTypeIcon( DataType _id , QString _icon ) { - initialize(); std::map::iterator index = typeToTypeInfo.find(_id); - if ( index != typeToTypeInfo.end() ) + if ( index != typeToTypeInfo.end() ) { 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; } /// Set the icon for a given dataType void setTypeIcon( QString _name , QString _icon ) { - initialize(); std::map::iterator index = stringToTypeInfo.find( _name ); - if ( index != stringToTypeInfo.end() ) + if ( index != stringToTypeInfo.end() ) { 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; } @@ -250,7 +262,6 @@ void setTypeIcon( QString _name , QString _icon ) { /// Get DataType Human readable name ( this name might change. Use the typeName insted! ) QString dataTypeName( DataType _id ) { - initialize(); std::map::iterator index = typeToTypeInfo.find(_id); @@ -264,7 +275,6 @@ QString dataTypeName( DataType _id ) { /// Get DataType Human readable name ( this name might change. Use the typeName insted! ) QString dataTypeName( QString _typeName ) { - initialize(); std::map::iterator index = stringToTypeInfo.find( _typeName ); @@ -280,7 +290,6 @@ QString dataTypeName( QString _typeName ) { /// Set the icon for a given dataType void setDataTypeName( DataType _id , QString _name ) { - initialize(); std::map::iterator index = typeToTypeInfo.find(_id); @@ -292,7 +301,6 @@ void setDataTypeName( DataType _id , QString _name ) { /// Set the icon for a given dataType void setDataTypeName( QString _typeName , QString _name ) { - initialize(); std::map::iterator index = stringToTypeInfo.find( _typeName ); diff --git a/common/Types.hh b/common/Types.hh index 86029bbe8164b15bd074a8d14a6671de4f066167..e65e2bc2b72e98fc83a0b87af206fa362f33bd84 100644 --- a/common/Types.hh +++ b/common/Types.hh @@ -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 -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 -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 DLLEXPORT diff --git a/common/TypesInternal.hh b/common/TypesInternal.hh new file mode 100644 index 0000000000000000000000000000000000000000..abe9cdf63d696ccebc251e9f50fe8afe5fd2137c --- /dev/null +++ b/common/TypesInternal.hh @@ -0,0 +1,71 @@ +/*===========================================================================*\ + * * + * 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 . * + * * +\*===========================================================================*/ + +/*===========================================================================*\ + * * + * $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 + +void initializeTypes(); + +//============================================================================= +#endif // TYPESINTERNAL_HH defined +//=============================================================================