#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <stdlib.h>
#ifdef LIBSBML_HAS_PACKAGE_RENDER
#endif
#if (!defined LIBSBML_HAS_PACKAGE_LAYOUT)
#error "This example requires libSBML to be built with the layout extension."
#endif
class LayoutConverter
{
public:
_doc = doc;
}
LayoutConverter(const char* filename) {
}
~LayoutConverter(){
delete _doc;
}
void convertLayout()
{
if (_doc == NULL || _doc->getModel() == NULL)
return;
if (_doc->getPlugin("layout") == NULL)
return;
if (_doc->getLevel() == 3)
convertLayoutToL2();
else
convertLayoutToL3();
}
void convertLayoutToL2()
{
if (_doc == NULL || _doc->getModel() == NULL)
return;
layoutNsUri = "http://projects.eml.org/bcb/sbml/level2";
#ifdef LIBSBML_HAS_PACKAGE_RENDER
foundRenderElements = false;
renderNsUri = "http://projects.eml.org/bcb/sbml/render/level2";
#endif
if (plugin == NULL)
return;
{
cout << "Conversion failed!" << endl;
_doc->printErrors();
exit(2);
}
if (docPlugin != NULL)
_doc->getSBMLNamespaces()->removePackageNamespace(3, 1, "layout", 1);
#ifdef LIBSBML_HAS_PACKAGE_RENDER
if (rdocPlugin!= NULL)
_doc->getSBMLNamespaces()->removePackageNamespace(3, 1, "render", 1);
#endif
}
void convertLayoutToL3()
{
if (_doc == NULL || _doc->getModel() == NULL)
return;
layoutNsUri = "http://www.sbml.org/sbml/level3/version1/layout/version1";
#ifdef LIBSBML_HAS_PACKAGE_RENDER
foundRenderElements = false;
renderNsUri = "http://www.sbml.org/sbml/level3/version1/render/version1";
#endif
if (plugin == NULL)
return;
{
cout << "Conversion failed!" << endl;
_doc->printErrors();
exit(2);
}
if (docPlugin != NULL)
_doc->getSBMLNamespaces()->addPackageNamespace("layout", 1);
_doc->setPackageRequired("layout", false);
#ifdef LIBSBML_HAS_PACKAGE_RENDER
if (!foundRenderElements)
return;
if (rdocPlugin != NULL)
{
_doc->getSBMLNamespaces()->addPackageNamespace("render", 1);
}
else
{
_doc->enablePackage(renderNsUri, "render", true);
}
_doc->setPackageRequired("render", false);
#endif
}
{
list->setSBMLNamespaces(layoutNs);
for (
unsigned int i = 0; i < list->
size(); i++)
#ifdef LIBSBML_HAS_PACKAGE_RENDER
if (lolPlugin != NULL)
{
}
#endif
}
#ifdef LIBSBML_HAS_PACKAGE_RENDER
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
foundRenderElements = true;
info->setSBMLNamespaces(renderNs);
}
{
foundRenderElements = true;
info->setSBMLNamespaces(renderNs);
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
color->setSBMLNamespaces(renderNs);
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
{
else
}
}
{
gradient->setSBMLNamespaces(renderNs);
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
stop->setSBMLNamespaces(renderNs);
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
line->setSBMLNamespaces(renderNs);
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
style->setSBMLNamespaces(renderNs);
}
{
style->setSBMLNamespaces(renderNs);
}
{
group->setSBMLNamespaces(renderNs);
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
{
{
break;
break;
break;
updateNs((
Image*)(current));
break;
break;
break;
updateNs((
Text*)(current));
break;
}
}
}
{
curve->setSBMLNamespaces(renderNs);
}
{
element->setSBMLNamespaces(renderNs);
}
{
element->setSBMLNamespaces(renderNs);
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
element->setSBMLNamespaces(renderNs);
}
{
list->setSBMLNamespaces(renderNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
#endif
{
list->setSBMLNamespaces(layoutNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
list->setSBMLNamespaces(layoutNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
list->setSBMLNamespaces(layoutNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
list->setSBMLNamespaces(layoutNs);
for (
unsigned int i = 0; i < list->
size(); i++)
{
else
updateNs(current);
}
}
{
list->setSBMLNamespaces(layoutNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
list->setSBMLNamespaces(layoutNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
list->setSBMLNamespaces(layoutNs);
for (
unsigned int i = 0; i < list->
size(); i++)
}
{
cubic->setSBMLNamespaces(layoutNs);
}
{
segment->setSBMLNamespaces(layoutNs);
}
{
glyph->setSBMLNamespaces(layoutNs);
}
{
glyph->setSBMLNamespaces(layoutNs);
}
{
glyph->setSBMLNamespaces(layoutNs);
}
{
glyph->setSBMLNamespaces(layoutNs);
}
{
glyph->setSBMLNamespaces(layoutNs);
}
void updateNs(
Curve *curve)
{
curve->setSBMLNamespaces(layoutNs);
}
{
glyph->setSBMLNamespaces(layoutNs);
}
{
box->setSBMLNamespaces(layoutNs);
}
{
dim->setSBMLNamespaces(layoutNs);
}
void updateNs(
Point *point)
{
point->setSBMLNamespaces(layoutNs);
}
{
layout->setSBMLNamespaces(layoutNs);
#ifdef LIBSBML_HAS_PACKAGE_RENDER
if (layoutPlugin != NULL)
{
updateNs(layoutPlugin->getListOfLocalRenderInformation());
}
#endif
}
protected:
#ifdef LIBSBML_HAS_PACKAGE_RENDER
string renderNsUri;
bool foundRenderElements;
#endif
string layoutNsUri;
};
class SimpleLayoutConverter
{
public:
_doc = doc;
}
SimpleLayoutConverter(const char* filename) {
}
~SimpleLayoutConverter(){
delete _doc;
}
void convertLayout()
{
if (_doc == NULL || _doc->getModel() == NULL)
return;
if (_doc->getPlugin("layout") == NULL)
return;
if (_doc->getLevel() == 3)
convertLayoutToL2();
else
convertLayoutToL3();
}
void convertLayoutToL2()
{
if (_doc == NULL || _doc->getModel() == NULL)
return;
layoutNsUri = "http://projects.eml.org/bcb/sbml/level2";
#ifdef LIBSBML_HAS_PACKAGE_RENDER
renderNsUri = "http://projects.eml.org/bcb/sbml/render/level2";
#endif
if (plugin == NULL)
return;
{
cout << "Conversion failed!" << endl;
_doc->printErrors();
exit(2);
}
if (docPlugin != NULL)
_doc->getSBMLNamespaces()->removePackageNamespace(3, 1, "layout", 1);
_doc->getSBMLNamespaces()->addPackageNamespace("layout", 1);
#ifdef LIBSBML_HAS_PACKAGE_RENDER
if (rdocPlugin!= NULL)
_doc->getSBMLNamespaces()->removePackageNamespace(3, 1, "render", 1);
_doc->getSBMLNamespaces()->addPackageNamespace("render", 1);
#endif
}
void convertLayoutToL3()
{
if (_doc == NULL || _doc->getModel() == NULL)
return;
layoutNsUri = "http://www.sbml.org/sbml/level3/version1/layout/version1";
#ifdef LIBSBML_HAS_PACKAGE_RENDER
renderNsUri = "http://www.sbml.org/sbml/level3/version1/render/version1";
#endif
if (plugin == NULL)
return;
{
cout << "Conversion failed!" << endl;
_doc->printErrors();
exit(2);
}
if (docPlugin != NULL)
_doc->getSBMLNamespaces()->addPackageNamespace("layout", 1);
_doc->setPackageRequired("layout", false);
#ifdef LIBSBML_HAS_PACKAGE_RENDER
if (rdocPlugin != NULL)
{
_doc->getSBMLNamespaces()->addPackageNamespace("render", 1);
}
else
{
_doc->enablePackage(renderNsUri, "render", true);
}
_doc->setPackageRequired("render", false);
#endif
}
protected:
#ifdef LIBSBML_HAS_PACKAGE_RENDER
string renderNsUri;
#endif
string layoutNsUri;
};
int main(int argc,char** argv)
{
if (argc != 3)
{
cerr << "usage convertLayout <input> <output>" << endl << endl;
cerr << "This converter converts the SBML Layout ";
#ifdef LIBSBML_HAS_PACKAGE_RENDER
cerr << "and Render ";
#endif
cerr << "package information between SBML Level 2 and Level 3." << endl << endl;
exit(1);
}
SimpleLayoutConverter converter(argv[1]);
converter.convertLayout();
}