/* * Returns an SBMLExtensionNamespaces<class SBMLExtensionType> object * (e.g. SBMLExtensionNamespaces<LayoutExtension> whose alias type is * LayoutPkgNamespaces) corresponding to the given uri. * Null will be returned if the given uri is not defined in the corresponding package. */ SBMLNamespaces* LayoutExtension::getSBMLExtensionNamespaces(const std::string &uri) const { LayoutPkgNamespaces* pkgns = NULL; if ( uri == getXmlnsL3V1V1()) { pkgns = new LayoutPkgNamespaces(3,1,1); } else if ( uri == getXmlnsL2()) { // // (NOTE) This should be harmless but may cause some problem. // pkgns = new LayoutPkgNamespaces(2); } return pkgns; }
/* * Returns the package version with the given URI of this package. */ unsigned int LayoutExtension::getPackageVersion(const std::string &uri) const { if (uri == getXmlnsL3V1V1()) { return 1; } else if (uri == getXmlnsL2()) { // // (NOTE) This should be harmless but may cause some problem. // return 1; } return 0; }
/* * Returns the SBML version with the given URI of this package. */ unsigned int LayoutExtension::getVersion(const std::string &uri) const { if (uri == getXmlnsL3V1V1()) { return 1; } else if (uri == getXmlnsL2()) { // // (NOTE) This may cause unexpected behaviour. // /* which indeed it does */ return 1; } return 0; }
/* * Returns the URI (namespace) of the package corresponding to the combination of the given sbml level, * sbml version, and package version. * Empty string will be returned if no corresponding URI exists. * * @return a string of the package URI */ const std::string& LayoutExtension::getURI(unsigned int sbmlLevel, unsigned int sbmlVersion, unsigned int pkgVersion) const { if (sbmlLevel == 3) { if (sbmlVersion == 1) { if (pkgVersion == 1) { return getXmlnsL3V1V1(); } } } else if (sbmlLevel == 2) { return getXmlnsL2(); } static std::string empty = ""; return empty; }
/* * * Initialization function of layout extension module which is automatically invoked * by SBMLExtensionRegister class before main() function invoked. * */ void LayoutExtension::init() { //------------------------------------------------------------------------- // // 1. Checks if the layout package has already been registered. // //------------------------------------------------------------------------- if (SBMLExtensionRegistry::getInstance().isRegistered(getPackageName())) { // do nothing; return; } //------------------------------------------------------------------------- // // 2. Creates an SBMLExtension derived object. // //------------------------------------------------------------------------- LayoutExtension layoutExtension; //------------------------------------------------------------------------------------- // // 3. Creates SBasePluginCreatorBase derived objects required for this extension. // The derived classes can be instantiated by using the following template class. // // temaplate<class SBasePluginType> class SBasePluginCreator // // The constructor of the creator class has two arguments: // // (1) SBaseExtensionPoint : extension point to which the plugin object connected // (2) std::vector<std::string> : a std::vector object that contains a list of URI // (package versions) supported by the plugin object. // // For example, three plugin classes (plugged in SBMLDocument, Model, and SpeciesReference) // are required for the layout extension (The plugin class for SpeciesReference is required // only for SBML Level 2) . // //--------------------------------------------------------------------------------------- std::vector<std::string> packageURIs; packageURIs.push_back(getXmlnsL3V1V1()); packageURIs.push_back(getXmlnsL2()); // // LayoutSpeciesReferencePlugin is used only for SBML Level 2 // std::vector<std::string> L2packageURI; L2packageURI.push_back(getXmlnsL2()); SBaseExtensionPoint sbmldocExtPoint("core",SBML_DOCUMENT); SBaseExtensionPoint modelExtPoint("core",SBML_MODEL); SBaseExtensionPoint sprExtPoint("core",SBML_SPECIES_REFERENCE); SBaseExtensionPoint msprExtPoint("core",SBML_MODIFIER_SPECIES_REFERENCE); SBasePluginCreator<LayoutSBMLDocumentPlugin, LayoutExtension> sbmldocPluginCreator(sbmldocExtPoint, packageURIs); SBasePluginCreator<LayoutModelPlugin, LayoutExtension> modelPluginCreator(modelExtPoint,packageURIs); SBasePluginCreator<LayoutSpeciesReferencePlugin, LayoutExtension> sprPluginCreator(sprExtPoint,L2packageURI); SBasePluginCreator<LayoutSpeciesReferencePlugin, LayoutExtension> msprPluginCreator(msprExtPoint,L2packageURI); //------------------------------------------------------------------------------------------ // // 4. Adds the above SBasePluginCreatorBase derived objects to the SBMLExtension derived object. // //------------------------------------------------------------------------------------------ layoutExtension.addSBasePluginCreator(&sbmldocPluginCreator); layoutExtension.addSBasePluginCreator(&modelPluginCreator); layoutExtension.addSBasePluginCreator(&sprPluginCreator); layoutExtension.addSBasePluginCreator(&msprPluginCreator); //------------------------------------------------------------------------- // // 5. Registers the SBMLExtension derived object to SBMLExtensionRegistry // //------------------------------------------------------------------------- int result = SBMLExtensionRegistry::getInstance().addExtension(&layoutExtension); if (result != LIBSBML_OPERATION_SUCCESS) { std::cerr << "[Error] LayoutExtension::init() failed." << std::endl; } }
/* * * Initialization function of groups extension module which is automatically invoked * by SBMLExtensionRegister class before main() function invoked. * */ void RenderExtension::init() { //------------------------------------------------------------------------- // // 1. Checks if the groups pacakge has already been registered. // //------------------------------------------------------------------------- if (SBMLExtensionRegistry::getInstance().isRegistered(getPackageName())) { // do nothing; return; } //------------------------------------------------------------------------- // // 2. Creates an SBMLExtension derived object. // //------------------------------------------------------------------------- RenderExtension renderExtension; //------------------------------------------------------------------------------------- // // 3. Creates SBasePluginCreatorBase derived objects required for this // extension. The derived classes can be instantiated by using the following // template class. // // temaplate<class SBasePluginType> class SBasePluginCreator // // The constructor of the creator class has two arguments: // // (1) SBaseExtensionPoint : extension point to which the plugin object connected // (2) std::vector<std::string> : a std::vector object that contains a list of URI // (package versions) supported by the plugin object. // // For example, two plugin objects (plugged in SBMLDocument and Model elements) are // required for the groups extension. // // Since only 'required' attribute is used in SBMLDocument by the groups package, existing // SBMLDocumentPluginNotRequired class can be used as-is for the plugin. // // Since the lists of supported package versions (currently only L3V1-groups-V1 supported ) // are equal in the both plugin objects, the same vector object is given to each // constructor. // //--------------------------------------------------------------------------------------- std::vector<std::string> packageURIs; packageURIs.push_back(getXmlnsL3V1V1()); packageURIs.push_back(getXmlnsL2()); // // LayoutSpeciesReferencePlugin is used only for SBML Level 2 // std::vector<std::string> L2packageURI; L2packageURI.push_back(getXmlnsL2()); SBaseExtensionPoint sbmldocExtPoint("core",SBML_DOCUMENT); SBaseExtensionPoint layoutExtPoint("layout",SBML_LAYOUT_LAYOUT); SBaseExtensionPoint layoutGOExtPoint("layout",SBML_LAYOUT_GRAPHICALOBJECT); SBaseExtensionPoint clayoutExtPoint("core",SBML_LAYOUT_LAYOUT); SBaseExtensionPoint listOfLayoutsExtPoint("layout", SBML_LIST_OF); SBasePluginCreator<RenderSBMLDocumentPlugin, RenderExtension> sbmldocPluginCreator(sbmldocExtPoint,packageURIs); SBasePluginCreator<RenderLayoutPlugin, RenderExtension> layoutPluginCreator(layoutExtPoint,packageURIs); SBasePluginCreator<RenderLayoutPlugin, RenderExtension> clayoutPluginCreator(clayoutExtPoint,packageURIs); SBasePluginCreator<RenderListOfLayoutsPlugin, RenderExtension> lolPluginCreator(listOfLayoutsExtPoint,packageURIs); SBasePluginCreator<RenderGraphicalObjectPlugin, RenderExtension> goPluginCreator(layoutGOExtPoint,packageURIs); //-------------------------------------------------------------------------------------- // // 3. Adds the above SBasePluginCreatorBase derived objects to the SBMLExtension derived object. // //-------------------------------------------------------------------------------------- renderExtension.addSBasePluginCreator(&sbmldocPluginCreator); renderExtension.addSBasePluginCreator(&layoutPluginCreator); renderExtension.addSBasePluginCreator(&clayoutPluginCreator); renderExtension.addSBasePluginCreator(&lolPluginCreator); renderExtension.addSBasePluginCreator(&goPluginCreator); //------------------------------------------------------------------------- // // 4. Registers the SBMLExtension derived object to SBMLExtensionRegistry // //------------------------------------------------------------------------- int result = SBMLExtensionRegistry::getInstance().addExtension(&renderExtension); if (result != LIBSBML_OPERATION_SUCCESS) { std::cerr << "[Error] RenderExtension::init() failed." << std::endl; } // add converter to registry; RenderLayoutConverter rlc; SBMLConverterRegistry::getInstance().addConverter(&rlc); }