libSBML C++ API
libSBML 5.18.0 C++ API
|
Converts SBML Layout and Render datra from SBML Level 2 to Level 3 and vice versa.
#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;
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);
updateNs(glyph->getListOfSpeciesReferenceGlyphs());
updateNs(glyph->getCurve());
}
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();
}
virtual RenderPoint * get(unsigned int n)
Get a RenderPoint from the ListOfCurveElements.
Definition: ListOfCurveElements.cpp:195
const ListOfCompartmentGlyphs * getListOfCompartmentGlyphs() const
Returns the ListOf object that holds all compartment glyphs.
Definition: Layout.cpp:535
A list of Layout objects.
Definition: Layout.h:1576
A list of LineSegment objects.
Definition: Curve.h:88
Spatial dimensions of a 2D or 3D shape.
Definition: Dimensions.h:65
A Cubic Bézier smooth curve.
Definition: CubicBezier.h:65
Representation of a point.
Definition: Point.h:59
A curve connecting elements in a diagram.
Definition: Curve.h:211
const ListOfLineSegments * getListOfCurveSegments() const
Returns a reference to the ListOf object that holds all the curve segments.
Definition: Curve.cpp:270
A list of LineEnding objects.
Definition: ListOfLineEndings.h:74
virtual LineSegment * get(unsigned int n)
Get a LineSegment from the ListOfLineSegments.
Definition: Curve.cpp:232
ListOfGlobalRenderInformation * getListOfGlobalRenderInformation()
Returns a pointer to the list object that contains local render information.
Definition: RenderListOfLayoutsPlugin.cpp:592
Include all SBML types in a single header file.
Extension of Model.
Definition: LayoutModelPlugin.h:62
Set of configuration option values for a converter.
Definition: ConversionProperties.h:78
A glyph for an SBML reaction.
Definition: ReactionGlyph.h:249
virtual LocalStyle * get(unsigned int n)
Get a LocalStyle from the ListOfLocalStyles.
Definition: ListOfLocalStyles.cpp:154
@ SBML_RENDER_IMAGE
Definition: RenderExtension.h:354
Representation of a linear gradient.
Definition: LinearGradient.h:80
@ SBML_LAYOUT_CUBICBEZIER
Definition: LayoutExtension.h:434
virtual int getTypeCode() const
Returns the libSBML type code of this object instance.
Definition: LineSegment.cpp:618
virtual CompartmentGlyph * get(unsigned int n)
Get a CompartmentGlyph from the ListOfCompartmentGlyphs.
Definition: Layout.cpp:2121
const ListOfLayouts * getListOfLayouts() const
Returns the ListOfLayouts object for this Model.
Definition: LayoutModelPlugin.cpp:361
LibSBML implementation for the extension to the Layout class by the Render extension.
Definition: RenderLayoutPlugin.h:61
const ListOfSpeciesGlyphs * getListOfSpeciesGlyphs() const
Returns the ListOf object that holds all species glyphs.
Definition: Layout.cpp:545
const ListOfGradientStops * getListOfGradientStops() const
Returns the ListOfGradientStops from this GradientBase.
const ListOfDrawables * getListOfElements() const
Returns the ListOfDrawables from this RenderGroup.
Definition: RenderGroup.cpp:970
@ SBML_RENDER_TEXT
Definition: RenderExtension.h:369
A list of SpeciesGlyph objects.
Definition: Layout.h:262
Curve * getCurve()
Returns the curve object for the species reference glyph.
Definition: SpeciesReferenceGlyph.cpp:365
virtual TextGlyph * get(unsigned int n)
Get a TextGlyph from the ListOfTextGlyphs.
Definition: Layout.cpp:2594
@ SBML_RENDER_CURVE
Definition: RenderExtension.h:367
const Point * getBasePoint1() const
Returns the first base point of the curve (the one closer to the starting point).
Definition: CubicBezier.cpp:382
@ SBML_RENDER_LINEARGRADIENT
Definition: RenderExtension.h:356
@ SBML_RENDER_GROUP
Definition: RenderExtension.h:353
A list of ReactionGlyph objects.
Definition: Layout.h:439
virtual ColorDefinition * get(unsigned int n)
Get a ColorDefinition from the ListOfColorDefinitions.
Definition: ListOfColorDefinitions.cpp:164
const BoundingBox * getBoundingBox() const
Returns the value of the "boundingBox" element of this LineEnding.
Definition: LineEnding.cpp:419
const RenderGroup * getGroup() const
Returns the value of the "group" element of this LineEnding.
Definition: LineEnding.cpp:399
virtual LineEnding * get(unsigned int n)
Get a LineEnding from the ListOfLineEndings.
Definition: ListOfLineEndings.cpp:166
Style information object used in LocalRenderInformation.
Definition: LocalStyle.h:76
Representation of images.
Definition: Image.h:80
virtual Layout * get(unsigned int n)
Get a Layout from the ListOfLayouts.
Definition: Layout.cpp:1939
Definition of RenderExtensionTypes.
unsigned int size() const
Returns number of items in this ListOf list.
Definition: ListOf.cpp:433
A list of GradientBase objects.
Definition: ListOfGradientDefinitions.h:75
Decoration element for the start and/or end of curves.
Definition: LineEnding.h:83
const ListOfGraphicalObjects * getListOfAdditionalGraphicalObjects() const
Returns the ListOf object that holds all additonal graphical objects.
Definition: Layout.cpp:575
A point with both absolute and relative values
Definition: RenderPoint.h:77
A glyph for an SBML species.
Definition: SpeciesGlyph.h:59
A list of Transformation2D objects.
Definition: ListOfDrawables.h:86
@ LIBSBML_OPERATION_SUCCESS
Definition: operationReturnValues.h:56
virtual Transformation2D * get(unsigned int n)
Get a Transformation2D from the ListOfDrawables.
Definition: ListOfDrawables.cpp:132
Representation of text elements.
Definition: Text.h:78
A list of curve elements.
Definition: ListOfCurveElements.h:78
const ListOfCurveElements * getListOfElements() const
Returns the ListOfCurveElements from this Polygon.
Definition: Polygon.cpp:325
const RenderGroup * getGroup() const
Returns the value of the "group" element of this Style.
Definition: Style.cpp:537
A list of TextGlyph objects.
Definition: Layout.h:616
virtual SpeciesGlyph * get(unsigned int n)
Get a SpeciesGlyph from the ListOfSpeciesGlyphs.
Definition: Layout.cpp:2273
Definition of SBMLDocumentPlugin, the derived class of SBasePlugin.
A color at a certain location in a color gradient.
Definition: GradientStop.h:86
const Point * getEnd() const
Returns the end point of the line.
Definition: LineSegment.cpp:349
Base class for extending SBMLDocument in packages.
Definition: SBMLDocumentPlugin.h:79
The layout of a diagram of an SBML model.
Definition: Layout.h:783
A list of GraphicalObject objects.
Definition: GraphicalObject.h:481
@ SBML_RENDER_RECTANGLE
Definition: RenderExtension.h:364
A list of LocalStyle objects.
Definition: ListOfLocalStyles.h:73
A group of graphical primitives creating a composite.
Definition: RenderGroup.h:80
virtual SpeciesReferenceGlyph * get(unsigned int n)
Get a SpeciesReferenceGlyph from the ListOfSpeciesReferenceGlyphs.
Definition: ReactionGlyph.cpp:904
const Point * getBasePoint2() const
Returns the second base point of the curve (the one closer to the end point).
Definition: CubicBezier.cpp:432
SBMLExtensionNamespaces< RenderExtension > RenderPkgNamespaces
Definition: RenderExtension.h:332
@ SBML_RENDER_POLYGON
Definition: RenderExtension.h:362
const ListOfCurveElements * getListOfElements() const
Returns the ListOfCurveElements from this RenderCurve.
Definition: RenderCurve.cpp:330
SBMLDocument_t * readSBMLFromFile(const char *filename)
Representation of a rectangle.
Definition: Rectangle.h:72
Include all SBML types of layout extension in a single header file.
Definition of an identifier for an RGBA color value.
Definition: ColorDefinition.h:87
A glyph for an SBML compartment.
Definition: CompartmentGlyph.h:54
A bounding box for an item in a diagram.
Definition: BoundingBox.h:58
virtual int getTypeCode() const
Returns the libSBML type code for this GradientBase object.
Definition: GradientBase.cpp:650
Representation of a line.
Definition: LineSegment.h:63
virtual GradientStop * get(unsigned int n)
Get a GradientStop from the ListOfGradientStops.
Definition: ListOfGradientStops.cpp:175
Representation of a Polygon
Definition: Polygon.h:77
const Point * getStart() const
Returns the start point of the line.
Definition: LineSegment.cpp:302
Representation of a radial gradient.
Definition: RadialGradient.h:83
A list of CompartmentGlyph objects.
Definition: Layout.h:84
virtual GlobalStyle * get(unsigned int n)
Get a GlobalStyle from the ListOfGlobalStyles.
Definition: ListOfGlobalStyles.cpp:154
A list of one or more GradientStop objects.
Definition: ListOfGradientStops.h:86
Representation of curves.
Definition: RenderCurve.h:83
Abstract base class for linear and radial gradients.
Definition: GradientBase.h:108
const ListOfTextGlyphs * getListOfTextGlyphs() const
Returns the ListOf object that holds all text glyphs.
Definition: Layout.cpp:565
BoundingBox * getBoundingBox()
Returns the bounding box for the GraphicalObject.
Definition: GraphicalObject.cpp:483
A list of GlobalStyle objects.
Definition: ListOfGlobalStyles.h:72
int setElementNamespace(const std::string &uri)
Sets the XML namespace to which this object belongs.
Definition: SBasePlugin.cpp:241
A list of ColorDefinition objects.
Definition: ListOfColorDefinitions.h:68
Set of SBML Level + Version + namespace triples.
Definition: SBMLNamespaces.h:139
A style that can be associated with a layout.
Definition: GlobalStyle.h:76
virtual GraphicalObject * get(unsigned int n)
Get a GraphicalObject from the ListOfGraphicalObjects.
Definition: GraphicalObject.cpp:1133
A glyph for a text label.
Definition: TextGlyph.h:59
A list of SpeciesReferenceGlyph objects.
Definition: ReactionGlyph.h:82
A glyph for an SBML species reference.
Definition: SpeciesReferenceGlyph.h:65
virtual ReactionGlyph * get(unsigned int n)
Get a ReactionGlyph from the ListOfReactionGlyphs.
Definition: Layout.cpp:2445
ListOfLocalRenderInformation * getListOfLocalRenderInformation()
Returns a pointer to the list object that contains local render information.
Definition: RenderLayoutPlugin.cpp:329
const Point * getPosition() const
Returns the position of the BoundingBox as const reference to a Point object.
Definition: BoundingBox.cpp:393
const ListOfReactionGlyphs * getListOfReactionGlyphs() const
Returns the ListOf object that holds all reaction glyphs.
Definition: Layout.cpp:555
const Dimensions * getDimensions() const
Returns the dimensions of the layout.
Definition: Layout.cpp:495
SBMLExtensionNamespaces< LayoutExtension > LayoutPkgNamespaces
Definition: LayoutExtension.h:417
@ SBML_RENDER_ELLIPSE
Definition: RenderExtension.h:348
A list of layout objects used by the "render" extension.
Definition: RenderListOfLayoutsPlugin.h:61
#define LIBSBML_CPP_NAMESPACE_USE
Definition: libsbml-namespace.h:67
Graphical representation of an ellipse.
Definition: Ellipse.h:75
Overall SBML container object.
Definition: SBMLDocument.h:342
Base class of objects that store layouts.
Definition: GraphicalObject.h:69
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:3460
virtual void addOption(const ConversionOption &option)
Adds a copy of the given option to this properties object.
Definition: ConversionProperties.cpp:226
int writeSBML(const SBMLDocument_t *d, const char *filename)
Writes the given SBML document d to the file named by filename.
virtual GradientBase * get(unsigned int n)
Get a GradientBase from the ListOfGradientDefinitions.
Definition: ListOfGradientDefinitions.cpp:174
const Dimensions * getDimensions() const
Returns the dimensions of the BoundingBox as const reference to a Dimensions object.
Definition: BoundingBox.cpp:404
Definition of ConversionProperties, the class encapsulating conversion configuration.