libSBML C++ API
libSBML 5.17.2 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)
{
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;
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:191
A list of Layout objects.
Definition: Layout.h:1572
A list of LineSegment objects.
Definition: Curve.h:84
Spatial dimensions of a 2D or 3D shape.
Definition: Dimensions.h:61
Curve * getCurve()
Returns the curve object for the species reference glyph.
Definition: SpeciesReferenceGlyph.cpp:361
A Cubic Bézier smooth curve.
Definition: CubicBezier.h:61
const ListOfSpeciesGlyphs * getListOfSpeciesGlyphs() const
Returns the ListOf object that holds all species glyphs.
Definition: Layout.cpp:541
Representation of a point.
Definition: Point.h:55
A curve connecting elements in a diagram.
Definition: Curve.h:207
A list of LineEnding objects.
Definition: ListOfLineEndings.h:70
virtual LineSegment * get(unsigned int n)
Get a LineSegment from the ListOfLineSegments.
Definition: Curve.cpp:228
Include all SBML types in a single header file.
Extension of Model.
Definition: LayoutModelPlugin.h:58
Set of configuration option values for a converter.
Definition: ConversionProperties.h:74
A glyph for an SBML reaction.
Definition: ReactionGlyph.h:245
virtual LocalStyle * get(unsigned int n)
Get a LocalStyle from the ListOfLocalStyles.
Definition: ListOfLocalStyles.cpp:150
Definition: RenderExtension.h:350
const ListOfReactionGlyphs * getListOfReactionGlyphs() const
Returns the ListOf object that holds all reaction glyphs.
Definition: Layout.cpp:551
Representation of a linear gradient.
Definition: LinearGradient.h:76
Definition: LayoutExtension.h:430
virtual int getTypeCode() const
Returns the libSBML type code of this object instance.
Definition: LineSegment.cpp:614
virtual CompartmentGlyph * get(unsigned int n)
Get a CompartmentGlyph from the ListOfCompartmentGlyphs.
Definition: Layout.cpp:2117
LibSBML implementation for the extension to the Layout class by the Render extension.
Definition: RenderLayoutPlugin.h:57
const ListOfGradientStops * getListOfGradientStops() const
Returns the ListOfGradientStops from this GradientBase.
Definition: RenderExtension.h:365
const RenderGroup * getGroup() const
Returns the value of the "group" element of this Style.
Definition: Style.cpp:533
A list of SpeciesGlyph objects.
Definition: Layout.h:258
virtual TextGlyph * get(unsigned int n)
Get a TextGlyph from the ListOfTextGlyphs.
Definition: Layout.cpp:2590
Definition: RenderExtension.h:363
Definition: RenderExtension.h:352
const ListOfCurveElements * getListOfElements() const
Returns the ListOfCurveElements from this Polygon.
Definition: Polygon.cpp:321
Definition: RenderExtension.h:349
A list of ReactionGlyph objects.
Definition: Layout.h:435
virtual ColorDefinition * get(unsigned int n)
Get a ColorDefinition from the ListOfColorDefinitions.
Definition: ListOfColorDefinitions.cpp:164
virtual LineEnding * get(unsigned int n)
Get a LineEnding from the ListOfLineEndings.
Definition: ListOfLineEndings.cpp:166
const Point * getBasePoint1() const
Returns the first base point of the curve (the one closer to the starting point).
Definition: CubicBezier.cpp:378
Style information object used in LocalRenderInformation.
Definition: LocalStyle.h:72
Representation of images.
Definition: Image.h:76
virtual Layout * get(unsigned int n)
Get a Layout from the ListOfLayouts.
Definition: Layout.cpp:1935
Definition of RenderExtensionTypes.
const Point * getBasePoint2() const
Returns the second base point of the curve (the one closer to the end point).
Definition: CubicBezier.cpp:428
unsigned int size() const
Returns number of items in this ListOf list.
Definition: ListOf.cpp:429
A list of GradientBase objects.
Definition: ListOfGradientDefinitions.h:71
Decoration element for the start and/or end of curves.
Definition: LineEnding.h:79
A point with both absolute and relative values
Definition: RenderPoint.h:73
A glyph for an SBML species.
Definition: SpeciesGlyph.h:55
A list of Transformation2D objects.
Definition: ListOfDrawables.h:82
Definition: operationReturnValues.h:52
virtual Transformation2D * get(unsigned int n)
Get a Transformation2D from the ListOfDrawables.
Definition: ListOfDrawables.cpp:128
Representation of text elements.
Definition: Text.h:74
A list of curve elements.
Definition: ListOfCurveElements.h:74
A list of TextGlyph objects.
Definition: Layout.h:612
virtual SpeciesGlyph * get(unsigned int n)
Get a SpeciesGlyph from the ListOfSpeciesGlyphs.
Definition: Layout.cpp:2269
Definition of SBMLDocumentPlugin, the derived class of SBasePlugin.
A color at a certain location in a color gradient.
Definition: GradientStop.h:82
const ListOfCurveElements * getListOfElements() const
Returns the ListOfCurveElements from this RenderCurve.
Definition: RenderCurve.cpp:326
Base class for extending SBMLDocument in packages.
Definition: SBMLDocumentPlugin.h:75
The layout of a diagram of an SBML model.
Definition: Layout.h:779
A list of GraphicalObject objects.
Definition: GraphicalObject.h:477
Definition: RenderExtension.h:360
A list of LocalStyle objects.
Definition: ListOfLocalStyles.h:69
const Dimensions * getDimensions() const
Returns the dimensions of the layout.
Definition: Layout.cpp:491
A group of graphical primitives creating a composite.
Definition: RenderGroup.h:76
const ListOfCompartmentGlyphs * getListOfCompartmentGlyphs() const
Returns the ListOf object that holds all compartment glyphs.
Definition: Layout.cpp:531
virtual SpeciesReferenceGlyph * get(unsigned int n)
Get a SpeciesReferenceGlyph from the ListOfSpeciesReferenceGlyphs.
Definition: ReactionGlyph.cpp:895
SBMLExtensionNamespaces< RenderExtension > RenderPkgNamespaces
Definition: RenderExtension.h:328
Definition: RenderExtension.h:358
SBMLDocument_t * readSBMLFromFile(const char *filename)
Representation of a rectangle.
Definition: Rectangle.h:68
Include all SBML types of layout extension in a single header file.
Definition of an identifier for an RGBA color value.
Definition: ColorDefinition.h:83
A glyph for an SBML compartment.
Definition: CompartmentGlyph.h:50
A bounding box for an item in a diagram.
Definition: BoundingBox.h:54
virtual int getTypeCode() const
Returns the libSBML type code for this GradientBase object.
Definition: GradientBase.cpp:647
const BoundingBox * getBoundingBox() const
Returns the value of the "boundingBox" element of this LineEnding.
Definition: LineEnding.cpp:415
const ListOfGraphicalObjects * getListOfAdditionalGraphicalObjects() const
Returns the ListOf object that holds all additonal graphical objects.
Definition: Layout.cpp:571
Representation of a line.
Definition: LineSegment.h:59
virtual GradientStop * get(unsigned int n)
Get a GradientStop from the ListOfGradientStops.
Definition: ListOfGradientStops.cpp:171
Representation of a Polygon
Definition: Polygon.h:73
Representation of a radial gradient.
Definition: RadialGradient.h:79
A list of CompartmentGlyph objects.
Definition: Layout.h:80
virtual GlobalStyle * get(unsigned int n)
Get a GlobalStyle from the ListOfGlobalStyles.
Definition: ListOfGlobalStyles.cpp:150
A list of one or more GradientStop objects.
Definition: ListOfGradientStops.h:82
Representation of curves.
Definition: RenderCurve.h:79
const RenderGroup * getGroup() const
Returns the value of the "group" element of this LineEnding.
Definition: LineEnding.cpp:395
Abstract base class for linear and radial gradients.
Definition: GradientBase.h:104
BoundingBox * getBoundingBox()
Returns the bounding box for the GraphicalObject.
Definition: GraphicalObject.cpp:489
A list of GlobalStyle objects.
Definition: ListOfGlobalStyles.h:68
int setElementNamespace(const std::string &uri)
Sets the XML namespace to which this object belongs.
Definition: SBasePlugin.cpp:237
const ListOfLineSegments * getListOfCurveSegments() const
Returns a reference to the ListOf object that holds all the curve segments.
Definition: Curve.cpp:266
A list of ColorDefinition objects.
Definition: ListOfColorDefinitions.h:68
Set of SBML Level + Version + namespace triples.
Definition: SBMLNamespaces.h:135
A style that can be associated with a layout.
Definition: GlobalStyle.h:72
const Point * getPosition() const
Returns the position of the BoundingBox as const reference to a Point object.
Definition: BoundingBox.cpp:389
virtual GraphicalObject * get(unsigned int n)
Get a GraphicalObject from the ListOfGraphicalObjects.
Definition: GraphicalObject.cpp:1129
A glyph for a text label.
Definition: TextGlyph.h:55
const ListOfDrawables * getListOfElements() const
Returns the ListOfDrawables from this RenderGroup.
Definition: RenderGroup.cpp:966
A list of SpeciesReferenceGlyph objects.
Definition: ReactionGlyph.h:78
A glyph for an SBML species reference.
Definition: SpeciesReferenceGlyph.h:61
const Point * getStart() const
Returns the start point of the line.
Definition: LineSegment.cpp:298
virtual ReactionGlyph * get(unsigned int n)
Get a ReactionGlyph from the ListOfReactionGlyphs.
Definition: Layout.cpp:2441
SBMLExtensionNamespaces< LayoutExtension > LayoutPkgNamespaces
Definition: LayoutExtension.h:413
Definition: RenderExtension.h:344
A list of layout objects used by the "render" extension.
Definition: RenderListOfLayoutsPlugin.h:57
const Point * getEnd() const
Returns the end point of the line.
Definition: LineSegment.cpp:345
const Dimensions * getDimensions() const
Returns the dimensions of the BoundingBox as const reference to a Dimensions object.
Definition: BoundingBox.cpp:400
#define LIBSBML_CPP_NAMESPACE_USE
Definition: libsbml-namespace.h:63
const ListOfTextGlyphs * getListOfTextGlyphs() const
Returns the ListOf object that holds all text glyphs.
Definition: Layout.cpp:561
Graphical representation of an ellipse.
Definition: Ellipse.h:71
Overall SBML container object.
Definition: SBMLDocument.h:338
const ListOfLayouts * getListOfLayouts() const
Returns the ListOfLayouts object for this Model.
Definition: LayoutModelPlugin.cpp:357
Base class of objects that store layouts.
Definition: GraphicalObject.h:65
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:3456
virtual void addOption(const ConversionOption &option)
Adds a copy of the given option to this properties object.
Definition: ConversionProperties.cpp:222
ListOfGlobalRenderInformation * getListOfGlobalRenderInformation()
Returns a pointer to the list object that contains local render information.
Definition: RenderListOfLayoutsPlugin.cpp:588
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
Definition of ConversionProperties, the class encapsulating conversion configuration.