#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
using namespace std;
LIBSBML_CPP_NAMESPACE_USE
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)
{
}
#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;
prop.addOption("strict", false);
prop.addOption("setLevelAndVersion", true);
prop.addOption("ignorePackages", true);
{
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;
prop.addOption("strict", false);
prop.addOption("setLevelAndVersion", true);
prop.addOption("ignorePackages", true);
{
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();
}
Definition of ConversionProperties, the class encapsulating conversion configuration.
SBMLExtensionNamespaces< LayoutExtension > LayoutPkgNamespaces
Definition: LayoutExtension.h:422
@ SBML_LAYOUT_CUBICBEZIER
Definition: LayoutExtension.h:439
Include all SBML types of layout extension in a single header file.
@ SBML_RENDER_POLYGON
Definition: RenderExtension.h:367
@ SBML_RENDER_RECTANGLE
Definition: RenderExtension.h:369
@ SBML_RENDER_GROUP
Definition: RenderExtension.h:358
@ SBML_RENDER_ELLIPSE
Definition: RenderExtension.h:353
@ SBML_RENDER_IMAGE
Definition: RenderExtension.h:359
@ SBML_RENDER_CURVE
Definition: RenderExtension.h:372
@ SBML_RENDER_TEXT
Definition: RenderExtension.h:374
@ SBML_RENDER_LINEARGRADIENT
Definition: RenderExtension.h:361
SBMLExtensionNamespaces< RenderExtension > RenderPkgNamespaces
Definition: RenderExtension.h:337
Definition of RenderExtensionTypes.
Definition of SBMLDocumentPlugin, the derived class of SBasePlugin.
SBMLDocument_t * readSBMLFromFile(const char *filename)
Reads an SBML document from the given file.
Include all SBML types in a single header file.
int writeSBML(const SBMLDocument_t *d, const char *filename)
Writes the given SBML document d to the file named by filename.
Definition: BoundingBox.h:64
const Point * getPosition() const
Returns the position of the BoundingBox as const reference to a Point object.
Definition: BoundingBox.cpp:398
const Dimensions * getDimensions() const
Returns the dimensions of the BoundingBox as const reference to a Dimensions object.
Definition: BoundingBox.cpp:409
Definition: ColorDefinition.h:93
Definition: CompartmentGlyph.h:60
Definition: ConversionProperties.h:84
virtual void addOption(const ConversionOption &option)
Adds a copy of the given option to this properties object.
Definition: ConversionProperties.cpp:232
Definition: CubicBezier.h:71
const Point * getBasePoint2() const
Returns the second base point of the curve (the one closer to the end point).
Definition: CubicBezier.cpp:437
const Point * getBasePoint1() const
Returns the first base point of the curve (the one closer to the starting point).
Definition: CubicBezier.cpp:387
const ListOfLineSegments * getListOfCurveSegments() const
Returns a reference to the ListOf object that holds all the curve segments.
Definition: Curve.cpp:275
Definition: Dimensions.h:71
Definition: GlobalStyle.h:82
Definition: GradientBase.h:114
virtual int getTypeCode() const
Returns the libSBML type code for this GradientBase object.
Definition: GradientBase.cpp:655
const ListOfGradientStops * getListOfGradientStops() const
Returns the ListOfGradientStops from this GradientBase.
Definition: GradientStop.h:92
Definition: GraphicalObject.h:75
BoundingBox * getBoundingBox()
Returns the bounding box for the GraphicalObject.
Definition: GraphicalObject.cpp:498
const ListOfCompartmentGlyphs * getListOfCompartmentGlyphs() const
Returns the ListOf object that holds all compartment glyphs.
Definition: Layout.cpp:540
const ListOfGraphicalObjects * getListOfAdditionalGraphicalObjects() const
Returns the ListOf object that holds all additonal graphical objects.
Definition: Layout.cpp:580
const ListOfReactionGlyphs * getListOfReactionGlyphs() const
Returns the ListOf object that holds all reaction glyphs.
Definition: Layout.cpp:560
const ListOfTextGlyphs * getListOfTextGlyphs() const
Returns the ListOf object that holds all text glyphs.
Definition: Layout.cpp:570
const Dimensions * getDimensions() const
Returns the dimensions of the layout.
Definition: Layout.cpp:500
const ListOfSpeciesGlyphs * getListOfSpeciesGlyphs() const
Returns the ListOf object that holds all species glyphs.
Definition: Layout.cpp:550
Definition: LayoutModelPlugin.h:68
const ListOfLayouts * getListOfLayouts() const
Returns the ListOfLayouts object for this Model.
Definition: LayoutModelPlugin.cpp:366
Definition: LineEnding.h:89
const RenderGroup * getGroup() const
Returns the value of the "group" element of this LineEnding.
Definition: LineEnding.cpp:409
const BoundingBox * getBoundingBox() const
Returns the value of the "boundingBox" element of this LineEnding.
Definition: LineEnding.cpp:429
Definition: LineSegment.h:69
const Point * getStart() const
Returns the start point of the line.
Definition: LineSegment.cpp:307
const Point * getEnd() const
Returns the end point of the line.
Definition: LineSegment.cpp:354
virtual int getTypeCode() const
Returns the libSBML type code of this object instance.
Definition: LineSegment.cpp:623
Definition: LinearGradient.h:86
Definition: ListOfColorDefinitions.h:74
virtual ColorDefinition * get(unsigned int n)
Get a ColorDefinition from the ListOfColorDefinitions.
Definition: ListOfColorDefinitions.cpp:169
virtual CompartmentGlyph * get(unsigned int n)
Get a CompartmentGlyph from the ListOfCompartmentGlyphs.
Definition: Layout.cpp:2126
Definition: ListOfCurveElements.h:84
virtual RenderPoint * get(unsigned int n)
Get a RenderPoint from the ListOfCurveElements.
Definition: ListOfCurveElements.cpp:200
Definition: ListOfDrawables.h:92
virtual Transformation2D * get(unsigned int n)
Get a Transformation2D from the ListOfDrawables.
Definition: ListOfDrawables.cpp:137
Definition: ListOfGlobalStyles.h:78
virtual GlobalStyle * get(unsigned int n)
Get a GlobalStyle from the ListOfGlobalStyles.
Definition: ListOfGlobalStyles.cpp:159
Definition: ListOfGradientDefinitions.h:81
virtual GradientBase * get(unsigned int n)
Get a GradientBase from the ListOfGradientDefinitions.
Definition: ListOfGradientDefinitions.cpp:179
Definition: ListOfGradientStops.h:92
virtual GradientStop * get(unsigned int n)
Get a GradientStop from the ListOfGradientStops.
Definition: ListOfGradientStops.cpp:180
Definition: GraphicalObject.h:487
virtual GraphicalObject * get(unsigned int n)
Get a GraphicalObject from the ListOfGraphicalObjects.
Definition: GraphicalObject.cpp:1138
unsigned int size() const
Returns number of items in this ListOf list.
Definition: ListOf.cpp:380
Definition: Layout.h:1582
virtual Layout * get(unsigned int n)
Get a Layout from the ListOfLayouts.
Definition: Layout.cpp:1944
Definition: ListOfLineEndings.h:80
virtual LineEnding * get(unsigned int n)
Get a LineEnding from the ListOfLineEndings.
Definition: ListOfLineEndings.cpp:171
virtual LineSegment * get(unsigned int n)
Get a LineSegment from the ListOfLineSegments.
Definition: Curve.cpp:237
Definition: ListOfLocalStyles.h:79
virtual LocalStyle * get(unsigned int n)
Get a LocalStyle from the ListOfLocalStyles.
Definition: ListOfLocalStyles.cpp:159
virtual ReactionGlyph * get(unsigned int n)
Get a ReactionGlyph from the ListOfReactionGlyphs.
Definition: Layout.cpp:2450
virtual SpeciesGlyph * get(unsigned int n)
Get a SpeciesGlyph from the ListOfSpeciesGlyphs.
Definition: Layout.cpp:2278
Definition: ReactionGlyph.h:88
virtual SpeciesReferenceGlyph * get(unsigned int n)
Get a SpeciesReferenceGlyph from the ListOfSpeciesReferenceGlyphs.
Definition: ReactionGlyph.cpp:909
virtual TextGlyph * get(unsigned int n)
Get a TextGlyph from the ListOfTextGlyphs.
Definition: Layout.cpp:2599
Definition: LocalStyle.h:82
const ListOfCurveElements * getListOfElements() const
Returns the ListOfCurveElements from this Polygon.
Definition: Polygon.cpp:330
Definition: RadialGradient.h:89
Definition: ReactionGlyph.h:255
const ListOfSpeciesReferenceGlyphs * getListOfSpeciesReferenceGlyphs() const
Returns the ListOf object that hold the species reference glyphs.
Definition: ReactionGlyph.cpp:353
const Curve * getCurve() const
Returns the curve object for the reaction glyph.
Definition: ReactionGlyph.cpp:452
Definition: Rectangle.h:78
Definition: RenderCurve.h:89
const ListOfCurveElements * getListOfElements() const
Returns the ListOfCurveElements from this RenderCurve.
Definition: RenderCurve.cpp:335
Definition: RenderGroup.h:86
const ListOfDrawables * getListOfElements() const
Returns the ListOfDrawables from this RenderGroup.
Definition: RenderGroup.cpp:975
Definition: RenderLayoutPlugin.h:67
ListOfLocalRenderInformation * getListOfLocalRenderInformation()
Returns a pointer to the list object that contains local render information.
Definition: RenderLayoutPlugin.cpp:334
Definition: RenderListOfLayoutsPlugin.h:67
ListOfGlobalRenderInformation * getListOfGlobalRenderInformation()
Returns a pointer to the list object that contains local render information.
Definition: RenderListOfLayoutsPlugin.cpp:597
Definition: RenderPoint.h:83
Definition: SBMLDocument.h:349
Definition: SBMLDocumentPlugin.h:85
Definition: SBMLNamespaces.h:145
SBasePlugin * getPlugin(const std::string &package)
Returns a plug-in object (extension interface) for an SBML Level 3 package extension with the given p...
Definition: SBase.cpp:3530
int setElementNamespace(const std::string &uri)
Sets the XML namespace to which this object belongs.
Definition: SBasePlugin.cpp:246
Definition: SpeciesGlyph.h:65
Definition: SpeciesReferenceGlyph.h:71
Curve * getCurve()
Returns the curve object for the species reference glyph.
Definition: SpeciesReferenceGlyph.cpp:370
const RenderGroup * getGroup() const
Returns the value of the "group" element of this Style.
Definition: Style.cpp:542
Definition: TextGlyph.h:65
@ LIBSBML_OPERATION_SUCCESS
Definition: operationReturnValues.h:61