5 #ifndef CNOID_BASE_ITEM_MANAGER_H 6 #define CNOID_BASE_ITEM_MANAGER_H 13 #include <boost/function.hpp> 24 class ItemManagerImpl;
46 void detachAllManagedTypeItemsFromRoot();
50 template <
class ItemType>
class Factory {
52 virtual Item* operator()() {
return new ItemType(); }
55 class CreationPanelFilterBase
58 virtual ~CreationPanelFilterBase() { }
59 virtual bool operator()(
Item* protoItem,
Item* parentItem) = 0;
61 typedef boost::shared_ptr<CreationPanelFilterBase> CreationPanelFilterBasePtr;
64 class FileFunctionBase
67 virtual ~FileFunctionBase() { }
68 virtual bool operator()(
Item* item,
const std::string& filename, std::ostream& os,
Item* parentItem) = 0;
70 typedef boost::shared_ptr<FileFunctionBase> FileFunctionBasePtr;
73 class OverwritingCheckFunctionBase
76 ~OverwritingCheckFunctionBase();
77 virtual bool operator()(
Item* item) = 0;
79 typedef boost::shared_ptr<OverwritingCheckFunctionBase> OverwritingCheckFunctionBasePtr;
84 void bindTextDomain(
const std::string& domain);
86 enum { PRIORITY_CONVERSION = -10, PRIORITY_OPTIONAL = 0, PRIORITY_DEFAULT = 10, PRIORITY_FORCE = 20 };
91 typedef boost::function<bool(ItemType* protoItem, Item* parentItem)>
Function;
94 return function(
static_cast<ItemType*
>(protoItem), parentItem);
103 typedef boost::function<bool(ItemType* item, const std::string& filename, std::ostream& os, Item* parentItem)>
Function;
105 virtual bool operator()(
Item* item,
const std::string& filename, std::ostream& os,
Item* parentItem){
106 return function(
static_cast<ItemType*
>(item), filename, os, parentItem);
113 registerClassSub(Factory<ItemType>(), 0,
typeid(ItemType).name(), className);
119 registerClassSub(0, singletonInstance,
typeid(ItemType).name(), className);
123 template <
class ItemType,
class BaseType>
128 static bool getClassIdentifier(ItemPtr item, std::string& out_moduleName, std::string& out_className);
131 return static_cast<ItemType*
>(getSingletonInstance(
typeid(ItemType).name()));
134 static ItemPtr create(
const std::string& moduleName,
const std::string& itemClassName);
137 addCreationPanelSub(
typeid(ItemType).name(), panel);
141 template <
class ItemType>
143 addCreationPanelFilterSub(
typeid(ItemType).name(),
148 template <
class ItemType>
150 addCreationPanelFilterSub(
typeid(ItemType).name(),
155 template <
class ItemType>
158 addLoaderSub(
typeid(ItemType).name(), caption, formatId, extensions,
163 template<
class ItemType>
164 ItemManager&
addSaver(
const std::string& caption,
const std::string& formatId,
const std::string& extensions,
166 addSaverSub(
typeid(ItemType).name(), caption, formatId, extensions,
171 template<
class ItemType>
173 const std::string& extensions,
176 int priority = PRIORITY_DEFAULT){
177 addLoader<ItemType>(caption, formatId, extensions, loadingFunction, priority);
178 addSaver<ItemType>(caption, formatId, extensions, savingFunction, priority);
182 void addMenuItemToImport(
const std::string& caption, boost::function<
void()> slot);
184 static void reloadItems(
const ItemList<>& items);
188 void registerClassSub(
189 boost::function<
Item*()> factory,
Item* singletonInstance,
const std::string& typeId,
const std::string& className);
191 void addCreationPanelFilterSub(
192 const std::string& typeId, CreationPanelFilterBasePtr filter,
bool afterInitializionByPanels);
193 void addLoaderSub(
const std::string& typeId,
const std::string& caption,
const std::string& formatId,
194 const std::string& extensions, FileFunctionBasePtr
function,
int priority);
195 void addSaverSub(
const std::string& typeId,
const std::string& caption,
const std::string& formatId,
196 const std::string& extensions, FileFunctionBasePtr
function,
int priority);
198 static Item* getSingletonInstance(
const std::string& typeId);
201 static bool load(
Item* item,
const std::string& filename,
Item* parentItem,
const std::string& formatId);
202 static bool save(
Item* item,
const std::string& filename,
const std::string& formatId);
203 static bool overwrite(
Item* item,
bool forceOverwrite,
const std::string& formatId);
206 friend class ItemManagerImpl;
207 ItemManagerImpl* impl;
Definition: ItemList.h:14
std::vector< std::string > getOpenFileNames(const std::string &caption, const std::string &extensions)
Definition: ItemManager.cpp:1437
FileFunction(Function function)
Definition: ItemManager.h:104
Definition: ItemManager.h:88
virtual bool initializeItem(Item *protoItem)=0
Definition: ItemManager.h:100
boost::function< bool(ItemType *protoItem, Item *parentItem)> Function
Definition: ItemManager.h:91
ItemManager & addLoader(const std::string &caption, const std::string &formatId, const std::string &extensions, const typename FileFunction< ItemType >::Function &function, int priority=PRIORITY_DEFAULT)
Definition: ItemManager.h:156
virtual bool initializePanel(Item *protoItem)=0
void registerDerivedClass(const std::string &className)
Definition: ItemManager.h:124
ItemManager & registerClass(const std::string &className, ItemType *singletonInstance)
This function registers a singleton item class.
Definition: ItemManager.h:118
virtual bool operator()(Item *protoItem, Item *parentItem)
Definition: ItemManager.h:93
ItemCreationPanel * findPanelOnTheSameDialog(const std::string &name)
Definition: ItemManager.cpp:695
Defines the minimum processing for performing pasing file for STL.
Definition: AbstractSceneLoader.h:9
static ItemType * singletonInstance()
Definition: ItemManager.h:130
ItemManager & registerClass(const std::string &className)
Definition: ItemManager.h:112
boost::function< bool(ItemType *item, const std::string &filename, std::ostream &os, Item *parentItem)> Function
Definition: ItemManager.h:103
std::string getOpenFileName(const std::string &caption, const std::string &extensions)
Definition: ItemManager.cpp:1417
ItemCreationPanel(QWidget *parent=0)
Definition: ItemManager.h:29
CreationPanelFilter(Function function)
Definition: ItemManager.h:92
#define CNOID_EXPORT
Definition: Util/exportdecl.h:37
ItemManager & addCreationPanel(ItemCreationPanel *panel=0)
Definition: ItemManager.h:136
void addCreationPanelPreFilter(const typename CreationPanelFilter< ItemType >::Function &filter)
Definition: ItemManager.h:142
Definition: ItemManager.h:26
void addCreationPanelPostFilter(const typename CreationPanelFilter< ItemType >::Function &filter)
Definition: ItemManager.h:149
Definition: ItemManager.h:39
ref_ptr< Item > ItemPtr
Definition: Item.h:20
ItemManager & addSaver(const std::string &caption, const std::string &formatId, const std::string &extensions, const typename FileFunction< ItemType >::Function &function, int priority=PRIORITY_DEFAULT)
Definition: ItemManager.h:164
virtual bool operator()(Item *item, const std::string &filename, std::ostream &os, Item *parentItem)
Definition: ItemManager.h:105
ItemManager & addLoaderAndSaver(const std::string &caption, const std::string &formatId, const std::string &extensions, const typename FileFunction< ItemType >::Function &loadingFunction, const typename FileFunction< ItemType >::Function &savingFunction, int priority=PRIORITY_DEFAULT)
Definition: ItemManager.h:172