TypeInterface.hh 7.19 KB
 Jan Möbius committed Nov 30, 2009 1 /*===========================================================================*\  Jan Möbius committed Nov 25, 2010 2 3 * * * OpenFlipper *  Jan Möbius committed Jan 26, 2011 4 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *  Jan Möbius committed Nov 25, 2010 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 * 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 . * * *  Jan Möbius committed Nov 30, 2009 33 34 35 \*===========================================================================*/ /*===========================================================================*\  Jan Möbius committed Nov 25, 2010 36 37 38 39 40 * * * $Revision$ * * $LastChangedBy$ * * $Date$ * * *  Jan Möbius committed Nov 30, 2009 41 42 43 44 45 46 47 48 \*===========================================================================*/ #ifndef TYPEINTERFACE_HH #define TYPEINTERFACE_HH #include  Jan Möbius committed Mar 01, 2011 49 50 51 52 53 54 /** \file TypeInterface.hh * * Interface for registering types in OpenFlipper. \ref typeInterfacePage */  Jan Möbius committed Nov 30, 2009 55  /** \brief Interface class for type definitions  Jan Möbius committed Mar 01, 2011 56 57 58 59 60 61 62 63 64  * * \n * \ref typeInterfacePage "Detailed description" * \n * * This interface is used to register new types in OpenFlipper. The type plugins are loaded before all other plugins. * They have only the registerType function which registers the type to the core and a function to add new * objects at runtime. */  Jan Möbius committed Nov 30, 2009 65 66 67  class TypeInterface {  68  signals:  Dirk Wilden committed Apr 11, 2011 69   70  /** \brief Emit this signal if an empty object has been created  Jan Möbius committed Mar 01, 2011 71 72 73 74  * * @param _id Id of the added object */ virtual void emptyObjectAdded( int _id ) {};  Dirk Wilden committed Apr 11, 2011 75   Jan Möbius committed Nov 30, 2009 76 77 78  public: /// Destructor  79  virtual ~TypeInterface() {};  Dirk Wilden committed Apr 11, 2011 80   81  public slots:  Jan Möbius committed Nov 30, 2009 82 83  virtual bool registerType() = 0;  Mike Kremer committed Dec 11, 2009 84 85 86 87 88 89 90 91 92 93  /** \brief Create an empty object * * When this slot is called you have to create an object of your supported type. * @return Id of the new Object */ virtual int addEmpty() = 0; /** \brief Return your supported object type( e.g. DATA_TRIANGLE_MESH ) *  Jan Möbius committed Mar 01, 2011 94 95  * The function is used from addEmpty in the core to check if your plugin can create an object of * a given dataType. If so, your addEmpty function will be invoked to create it.  Mike Kremer committed Dec 11, 2009 96 97  */ virtual DataType supportedType() = 0;  Dirk Wilden committed Apr 11, 2011 98 99 100 101 102 103 104 105 106  /** \brief This slot should be implemented in a TypePlugin to generate type specific backups * * @param _id Id of the added object * @param _name name of the backup * @param _type the type of backup that needs to be done */ virtual void generateBackup( int _id, QString _name, UpdateType _type ){};  Jan Möbius committed Nov 30, 2009 107 108 };  Jan Möbius committed Mar 01, 2011 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186  /** \page typeInterfacePage Type Interface \n \image html TypeInterface.png \n This interface is used to register new types in OpenFlipper. The type plugins are loaded before all other plugins. They have only the registerType function which registers the type to the core and a function to create objects of the new type. The type itself has to be defined in the ObjectTypes subdirectory. \section TypeExample Example using custom data types Adding a custom data type to %OpenFlipper needs the following requirements in order to work: - The definition of the typeId constant, e.g.: \code #define DATA_MY_DATA typeId("MyDataType") \endcode Note: Your data type is then referenced as DATA_MY_DATA during runtime. - The specification of an object class for your object type that is derived from BaseObjectData. - The specification of helper functions (usually within the PluginFunctions namespace) allowing the casting from BaseObjectData to your object type class. See detailed examples for each of the three points for already existing data types in OpenFlipperRoot/ObjectTypes. Once the object class is specified, the type plugin will be responsible for its handling including - Adding new objects to the scenegraph - Setting the initial name of an object - Etc. So, type plugins usually consist of only few lines of code. Here an example of a type plugin handling an example object data type as mentioned above: \code bool MyDataTypePlugin::registerType() { addDataType("MyDataType",tr("MyDataType")); setTypeIcon( "MyDataType", "myDataType.png"); return true; } int MyDataTypePlugin::addEmpty() { // Create new object MyObject* object = new MyObject(); object->setName( QString("My Object %1.mob").arg(objectCount) ); object->update(); object->show(); // Tell core that an object has been added emit emptyObjectAdded ( object->id() ); return object->id(); } \endcode Now, each time a plugin emits addEmptyObject(DATA_MY_DATA), the addEmpty() function will add the object to the scenegraph and return the newly created object's id. To use the TypeInterface:
*/  Jan Möbius committed Feb 25, 2011 187 Q_DECLARE_INTERFACE(TypeInterface,"OpenFlipper.TypeInterface/1.1")  Jan Möbius committed Nov 30, 2009 188 189  #endif // TYPEINTERFACE_HH