builderext/PluggableBuilderExtension.hpp
Go to the documentation of this file.
00001 /*
00002   This file is part of OpenFLUID software
00003   Copyright (c) 2007-2010 INRA-Montpellier SupAgro
00004 
00005 
00006  == GNU General Public License Usage ==
00007 
00008   OpenFLUID is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012 
00013   OpenFLUID is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   along with OpenFLUID.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021   In addition, as a special exception, INRA gives You the additional right
00022   to dynamically link the code of OpenFLUID with code not covered
00023   under the GNU General Public License ("Non-GPL Code") and to distribute
00024   linked combinations including the two, subject to the limitations in this
00025   paragraph. Non-GPL Code permitted under this exception must only link to
00026   the code of OpenFLUID dynamically through the OpenFLUID libraries
00027   interfaces, and only for building OpenFLUID plugins. The files of
00028   Non-GPL Code may be link to the OpenFLUID libraries without causing the
00029   resulting work to be covered by the GNU General Public License. You must
00030   obey the GNU General Public License in all respects for all of the
00031   OpenFLUID code and other code used in conjunction with OpenFLUID
00032   except the Non-GPL Code covered by this exception. If you modify
00033   this OpenFLUID, you may extend this exception to your version of the file,
00034   but you are not obligated to do so. If you do not wish to provide this
00035   exception without modification, you must delete this exception statement
00036   from your version and license this OpenFLUID solely under the GPL without
00037   exception.
00038 
00039 
00040  == Other Usage ==
00041 
00042   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00043   license, and requires a written agreement between You and INRA.
00044   Licensees for Other Usage of OpenFLUID may use this file in accordance
00045   with the terms contained in the written agreement between You and INRA.
00046 */
00047 
00056 #include <string>
00057 #include <set>
00058 
00059 #ifndef __PLUGGABLEBUILDEREXTENSION_HPP__
00060 #define __PLUGGABLEBUILDEREXTENSION_HPP__
00061 
00062 
00063 #include <gtkmm/widget.h>
00064 
00065 #include <boost/preprocessor/seq/for_each.hpp>
00066 #include <boost/preprocessor/seq/elem.hpp>
00067 #include <boost/preprocessor/seq/push_back.hpp>
00068 #include <boost/preprocessor/comparison/equal.hpp>
00069 
00070 #include <openfluid/dllexport.hpp>
00071 #include <openfluid/config.hpp>
00072 #include <openfluid/machine/SimulationBlob.hpp>
00073 #include <openfluid/machine/ModelInstance.hpp>
00074 #include <openfluid/guicommon/PreferencesPanel.hpp>
00075 
00076 
00077 // =====================================================================
00078 // =====================================================================
00079 
00083 #define EXTENSION_PROC_NAME "GetExtension"
00084 
00088 #define EXTINFOS_PROC_NAME "GetExtensionInfos"
00089 
00093 #define EXTPREFS_PROC_NAME "GetExtensionPrefs"
00094 
00098 #define EXTSDKVERSION_PROC_NAME "GetExtensionSDKVersion"
00099 
00100 
00101 // =====================================================================
00102 // =====================================================================
00103 
00104 
00108 #define DECLARE_EXTENSION_HOOKS \
00109   extern "C" \
00110   { \
00111     DLLEXPORT std::string GetExtensionSDKVersion(); \
00112     DLLEXPORT openfluid::builderext::PluggableBuilderExtension* GetExtension(); \
00113     DLLEXPORT openfluid::builderext::BuilderExtensionInfos GetExtensionInfos(); \
00114     DLLEXPORT openfluid::builderext::BuilderExtensionPrefs* GetExtensionPrefs(); \
00115     DLLEXPORT std::set<std::string> GetDefaultConfig(); \
00116   }
00117 
00118 
00119 #define EXT_PREFS_CLASS_DEFINED(seq) \
00120   BOOST_PP_EQUAL(BOOST_PP_SEQ_SIZE(seq),2)
00121 
00122 #define EXT_RETURN_NEW(list) \
00123   return new BOOST_PP_SEQ_ELEM(1,BOOST_PP_SEQ_PUSH_BACK(list,dummy))();
00124 
00125 #define EXT_RETURN_NULL return (openfluid::builderext::BuilderExtensionPrefs*)0;
00126 
00133 #define DEFINE_EXTENSION_HOOKS(pluginclassnames) \
00134   std::string GetExtensionSDKVersion() \
00135   { \
00136     return std::string(openfluid::config::FULL_VERSION); \
00137   } \
00138   \
00139   openfluid::builderext::PluggableBuilderExtension* GetExtension() \
00140   { \
00141     openfluid::builderext::PluggableBuilderExtension* Ext = new BOOST_PP_SEQ_ELEM(0,pluginclassnames)(); \
00142       Ext->setDefaultConfiguration(GetDefaultConfig()); \
00143     return Ext; \
00144   } \
00145   \
00146   openfluid::builderext::BuilderExtensionPrefs* GetExtensionPrefs() \
00147   { \
00148     BOOST_PP_IF(EXT_PREFS_CLASS_DEFINED(pluginclassnames),EXT_RETURN_NEW(pluginclassnames),EXT_RETURN_NULL) \
00149   }
00150 
00151 #define DEFINE_EXTENSION_INFOS(id,shortname,name,desc,authors,authorsctct,type) \
00152   openfluid::builderext::BuilderExtensionInfos GetExtensionInfos() \
00153   { \
00154     openfluid::builderext::BuilderExtensionInfos BEI; \
00155     \
00156     BEI.ID = (id); \
00157     BEI.ShortName = (shortname); \
00158     BEI.Name = (name); \
00159     BEI.Description = (desc); \
00160     BEI.Authors = (authors); \
00161     BEI.AuthorsContact = (authorsctct); \
00162     BEI.Type = (type); \
00163     \
00164     return BEI; \
00165   }
00166 
00167 
00168 #define ADD_TO_SET(r,data,elem) \
00169   data.insert(elem);
00170 
00171 #define DEFINE_EXTENSION_DEFAULT_CONFIG(seq)       \
00172     std::set<std::string> GetDefaultConfig()       \
00173     {                                              \
00174       std::set<std::string> config;                \
00175       BOOST_PP_SEQ_FOR_EACH(ADD_TO_SET,config,seq) \
00176       return config;                               \
00177     }
00178 
00179 
00180 // =====================================================================
00181 // =====================================================================
00182 
00183 
00184 namespace openfluid { namespace builderext {
00185 
00186 
00187 
00188 typedef std::map<std::string,std::string> ExtensionConfig_t;
00189 
00190 
00191 // =====================================================================
00192 // =====================================================================
00193 
00194 
00195 class PluggableBuilderExtension
00196 {
00197   protected:
00198 
00199     ExtensionConfig_t m_Config;
00200 
00201     sigc::signal<void> m_signal_ChangedOccurs;
00202 
00203     openfluid::machine::SimulationBlob* mp_SimulationBlob;
00204 
00205     openfluid::machine::ModelInstance* mp_ModelInstance;
00206 
00207 
00208   public:
00209 
00210     enum ExtensionType { WorkspaceTab, ModelessWindow, ModalWindow,
00211                          SpatialgraphImporter, InputdataImporter, EventsImporter, ExtraImporter, MixedImporter,
00212                          SimulationListener, HomeLauncher };
00213 
00214 
00215     PluggableBuilderExtension() : mp_SimulationBlob(NULL) { };
00216 
00217 
00218     virtual ~PluggableBuilderExtension() { };
00219 
00220 
00221     void setSimulationBlobAndModel(openfluid::machine::SimulationBlob* Blob, openfluid::machine::ModelInstance* Model)
00222       { mp_SimulationBlob = Blob; mp_ModelInstance = Model; };
00223 
00224 
00225     sigc::signal<void> signal_ChangedOccurs()
00226     {
00227       return m_signal_ChangedOccurs;
00228     }
00229 
00230     void setDefaultConfiguration(std::set<std::string> DefaultConfig)
00231     {
00232       for(std::set<std::string>::iterator it = DefaultConfig.begin() ; it != DefaultConfig.end() ; ++it)
00233       {
00234         std::vector<std::string> Splitted = openfluid::tools::SplitString(*it,"=");
00235 
00236         if(Splitted.size() != 2)
00237           throw openfluid::base::OFException("OpenFLUID framework","PluggableBuilderExtension::setDefaultConfig",
00238               "Configuration element \"" + Splitted[0] + "\" is not well formatted.");
00239 
00240         m_Config[Splitted[0]] = Splitted[1];
00241       }
00242     }
00243 
00248     virtual ExtensionType getType() const = 0;
00249 
00250 
00255     virtual bool isConfigurable() { return false; };
00256 
00257 
00262     ExtensionConfig_t getConfiguration() const { return m_Config; };
00263 
00264 
00269     void setConfiguration(const ExtensionConfig_t& Config) { m_Config = Config; };
00270 
00271 
00278     virtual Gtk::Widget* getExtensionAsWidget() = 0;
00279 
00280 
00281     virtual void show() = 0;
00282 
00283 
00289     virtual bool isReadyForShowtime() const { return false; };
00290 
00291 };
00292 
00293 
00294 // =====================================================================
00295 // =====================================================================
00296 
00297 
00298 class DLLEXPORT BuilderExtensionInfos
00299 {
00300   public:
00301 
00302     std::string ID;
00303 
00304     std::string Name;
00305 
00306     std::string ShortName;
00307 
00308     std::string Description;
00309 
00310     std::string Authors;
00311 
00312     std::string AuthorsContact;
00313 
00314     PluggableBuilderExtension::ExtensionType Type;
00315 
00316     BuilderExtensionInfos()
00317     : ID(""), Name(""), ShortName(""), Description(""), Authors(""), AuthorsContact(""),
00318       Type(PluggableBuilderExtension::ModalWindow)
00319     {
00320 
00321     }
00322 };
00323 
00324 
00325 // =====================================================================
00326 // =====================================================================
00327 
00328 
00329 class BuilderExtensionPrefs : public openfluid::guicommon::PreferencesPanel
00330 {
00331   public:
00332 
00333     BuilderExtensionPrefs(Glib::ustring PanelTitle) :
00334       openfluid::guicommon::PreferencesPanel(PanelTitle) { };
00335 
00336     virtual ~BuilderExtensionPrefs() { };
00337 
00338 };
00339 
00340 
00341 // =====================================================================
00342 // =====================================================================
00343 
00344 
00345 typedef PluggableBuilderExtension* (*GetExtensionProc)();
00346 
00347 typedef BuilderExtensionInfos (*GetExtensionInfosProc)();
00348 
00349 typedef BuilderExtensionPrefs* (*GetExtensionPrefsProc)();
00350 
00351 typedef std::string (*GetExtensionSDKVersionProc)();
00352 
00353 
00354 } } // namespaces
00355 
00356 #endif /* __PLUGGABLEBUILDEREXTENSION_HPP__ */

Generated using Doxygen 1.7.6.1
Creative Commons License Creative Commons By-NC-ND license