1 /**
2  * @file    RenderExtension.cpp
3  * @brief   Implementation of RenderExtension, the core module of the render package.
4  * @author  Frank T. Bergmann
5  *
6  *<!---------------------------------------------------------------------------
7  * This file is part of libSBML.  Please visit http://sbml.org for more
8  * information about SBML, and the latest version of libSBML.
9  *
10  * Copyright (C) 2020 jointly by the following organizations:
11  *     1. California Institute of Technology, Pasadena, CA, USA
12  *     2. University of Heidelberg, Heidelberg, Germany
13  *     3. University College London, London, UK
14  *
15  * Copyright (C) 2019 jointly by the following organizations:
16  *     1. California Institute of Technology, Pasadena, CA, USA
17  *     2. University of Heidelberg, Heidelberg, Germany
18  *
19  * Copyright (C) 2013-2018 jointly by the following organizations:
20  *     1. California Institute of Technology, Pasadena, CA, USA
21  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22  *     3. University of Heidelberg, Heidelberg, Germany
23  *
24  * Copyright (C) 2009-2013 jointly by the following organizations:
25  *     1. California Institute of Technology, Pasadena, CA, USA
26  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27  *
28  * This library is free software; you can redistribute it and/or modify it
29  * under the terms of the GNU Lesser General Public License as published by
30  * the Free Software Foundation.  A copy of the license agreement is provided
31  * in the file named "LICENSE.txt" included with this software distribution
32  * and also available online as http://sbml.org/software/libsbml/license.html
33  *------------------------------------------------------------------------- -->
34  */
35 
36 #include <sbml/extension/SBMLExtensionRegister.h>
37 #include <sbml/extension/SBMLExtensionRegistry.h>
38 #include <sbml/extension/SBasePluginCreator.h>
39 
40 #include <sbml/packages/render/extension/RenderExtension.h>
41 #include <sbml/packages/layout/extension/LayoutExtension.h>
42 #include <sbml/packages/layout/extension/LayoutModelPlugin.h>
43 #include <sbml/packages/render/extension/RenderListOfLayoutsPlugin.h>
44 #include <sbml/packages/render/validator/RenderSBMLErrorTable.h>
45 #include <sbml/packages/render/extension/RenderGraphicalObjectPlugin.h>
46 #include <sbml/packages/render/extension/RenderSBMLDocumentPlugin.h>
47 #include <sbml/SBMLDocument.h>
48 #include <sbml/packages/render/extension/RenderLayoutPlugin.h>
49 #include <sbml/conversion/SBMLConverter.h>
50 #include <sbml/conversion/SBMLConverterRegistry.h>
51 #include <sbml/packages/render/util/RenderLayoutConverter.h>
52 
53 #ifdef __cplusplus
54 
55 #include <iostream>
56 #include <string>
57 
58 LIBSBML_CPP_NAMESPACE_BEGIN
59 
60 // -------------------------------------------------------------------------
61 //
62 // This block is global initialization code which should be automatically
63 // executed before invoking main() block.
64 //
65 // -------------------------------------------------------------------------
66 
67 //------------- (START) -----------------------------------
68 
69 // The name of this package
70 
getPackageName()71 const std::string& RenderExtension::getPackageName ()
72 {
73   static const std::string pkgName = "render";
74   return pkgName;
75 }
76 
77 //
78 // Default SBML level, version, and package version
79 //
getDefaultLevel()80 unsigned int RenderExtension::getDefaultLevel()
81 {
82   return 3;
83 }
84 
getDefaultVersion()85 unsigned int RenderExtension::getDefaultVersion()
86 {
87   return 1;
88 }
89 
getDefaultPackageVersion()90 unsigned int RenderExtension::getDefaultPackageVersion()
91 {
92   return 1;
93 }
94 
95 //
96 // XML namespaces of (1) package versions of groups extension, and
97 // (2) another XML namespace(XMLSchema-instance) required in the groups
98 //  extension.
99 //
100 
getXmlnsL3V1V1()101 const std::string& RenderExtension::getXmlnsL3V1V1 ()
102 {
103   static const std::string xmlns = "http://www.sbml.org/sbml/level3/version1/render/version1";
104   return xmlns;
105 }
106 
getXmlnsL2()107 const std::string& RenderExtension::getXmlnsL2 ()
108 {
109   static const std::string xmlns = "http://projects.eml.org/bcb/sbml/render/level2";
110   return xmlns;
111 }
112 
113 
114 //
115 // Adds this RenderExtension object to the SBMLExtensionRegistry class.
116 // RenderExtension::init() function is automatically invoked when this
117 // object is instantiated.
118 //
119 static SBMLExtensionRegister<RenderExtension> renderExtensionRegister;
120 
121 static
122 const char* SBML_RENDER_TYPECODE_STRINGS[] =
123 {
124     "ColorDefinition"
125   , "Ellipse"
126   , "GlobalRenderInformation"
127   , "GlobalStyle"
128   , "GradientDefinition"
129   , "GradientStop"
130   , "Group"
131   , "Image"
132   , "LineEnding"
133   , "LinearGradient"
134   , "LineSegment"
135   , "ListOfGlobalStyles"
136   , "ListOfLocalStyles"
137   , "LocalRenderInformation"
138   , "LocalStyle"
139   , "Polygon"
140   , "RadialGradient"
141   , "Rectangle"
142   , "RelAbsVector"
143   , "CubicBezier"
144   , "Curve"
145   , "Point"
146   , "Text"
147   , "Transformation2D"
148   , "DefaultValues"
149 
150 };
151 
152 //------------- (END) -----------------------------------
153 
154 // --------------------------------------------------------
155 //
156 // Instantiate SBMLExtensionNamespaces<RenderExtension>
157 // (RenderPkgNamespaces) for DLL.
158 //
159 // --------------------------------------------------------
160 
161 template class LIBSBML_EXTERN SBMLExtensionNamespaces<RenderExtension>;
162 
163 
164 
RenderExtension()165 RenderExtension::RenderExtension ()
166 {
167 }
168 
169 
170 /*
171  * Copy constructor.
172  */
RenderExtension(const RenderExtension & orig)173 RenderExtension::RenderExtension(const RenderExtension& orig)
174 : SBMLExtension(orig)
175 {
176 }
177 
178 
179 /*
180  * Destroy this object.
181  */
~RenderExtension()182 RenderExtension::~RenderExtension ()
183 {
184 }
185 
186 
187 /*
188  * Assignment operator for RenderExtension.
189  */
190 RenderExtension&
operator =(const RenderExtension & orig)191 RenderExtension::operator=(const RenderExtension& orig)
192 {
193   SBMLExtension::operator=(orig);
194   return *this;
195 }
196 
197 
198 /*
199  * Creates and returns a deep copy of this RenderExtension object.
200  *
201  * @return a (deep) copy of this RenderExtension object
202  */
203 RenderExtension*
clone() const204 RenderExtension::clone () const
205 {
206   return new RenderExtension(*this);
207 }
208 
209 
210 const std::string&
getName() const211 RenderExtension::getName() const
212 {
213   return getPackageName();
214 }
215 
216 
217 /*
218  * Returns the URI (namespace) of the package corresponding to the combination of the given sbml level,
219  * sbml version, and package version.
220  * Empty string will be returned if no corresponding URI exists.
221  *
222  * @return a string of the package URI
223  */
224 const std::string&
getURI(unsigned int sbmlLevel,unsigned int sbmlVersion,unsigned int pkgVersion) const225 RenderExtension::getURI(unsigned int sbmlLevel, unsigned int sbmlVersion, unsigned int pkgVersion) const
226 {
227   if (sbmlLevel == 3)
228   {
229     if (sbmlVersion == 1 || sbmlVersion == 2)
230     {
231       if (pkgVersion == 1)
232       {
233         return getXmlnsL3V1V1();
234       }
235     }
236   }
237   else if (sbmlLevel == 2)
238   {
239     return getXmlnsL2();
240   }
241 
242   static std::string empty = "";
243 
244   return empty;
245 }
246 
247 
248 /*
249  * Returns the SBML level with the given URI of this package.
250  *
251  *  (NOTICE) Package developers MUST OVERRIDE this pure virtual function in their derived class.
252  *
253  */
254 unsigned int
getLevel(const std::string & uri) const255 RenderExtension::getLevel(const std::string &uri) const
256 {
257   if (uri == getXmlnsL3V1V1())
258   {
259     return 3;
260   }
261   else if (uri == getXmlnsL2())
262   {
263     return 2;
264   }
265 
266   return 0;
267 }
268 
269 
270 /*
271  * Returns the SBML version with the given URI of this package.
272  *
273  *  (NOTICE) Package developers MUST OVERRIDE this pure virtual function in their derived class.
274  *
275  */
276 unsigned int
getVersion(const std::string & uri) const277 RenderExtension::getVersion(const std::string &uri) const
278 {
279   if (uri == getXmlnsL3V1V1())
280   {
281     return 1;
282   }
283   else if (uri == getXmlnsL2())
284   {
285     //
286     // (NOTE) This may cause unexpected behaviour.
287     //
288     /* which indeed it does */
289     return 1;
290   }
291 
292   return 0;
293 }
294 
295 
296 /*
297  * Returns the package version with the given URI of this package.
298  *
299  *  (NOTICE) Package developers MUST OVERRIDE this pure virtual function in their derived class.
300  *
301  */
302 unsigned int
getPackageVersion(const std::string & uri) const303 RenderExtension::getPackageVersion(const std::string &uri) const
304 {
305   if (uri == getXmlnsL3V1V1())
306   {
307     return 1;
308   }
309   else if (uri == getXmlnsL2())
310   {
311     //
312     // (NOTE) This should be harmless but may cause some problem.
313     //
314     return 1;
315   }
316 
317   return 0;
318 }
319 
320 
321 /*
322  * Returns an SBMLExtensionNamespaces<class SBMLExtensionType> object
323  * (e.g. SBMLExtensionNamespaces<RenderExtension> whose alias type is
324  * RenderPkgNamespaces) corresponding to the given uri.
325  * NULL will be returned if the given uri is not defined in the corresponding package.
326  *
327  *  (NOTICE) Package developers MUST OVERRIDE this pure virtual function in their derived class.
328  *
329  */
330 SBMLNamespaces*
getSBMLExtensionNamespaces(const std::string & uri) const331 RenderExtension::getSBMLExtensionNamespaces(const std::string &uri) const
332 {
333   RenderPkgNamespaces* pkgns = NULL;
334 
335   if (uri == getXmlnsL3V1V1())
336   {
337     pkgns = new RenderPkgNamespaces(3, 1, 1);
338   }
339   else if ( uri == getXmlnsL2())
340   {
341     //
342     // (NOTE) This should be harmless but may cause some problem.
343     //
344     pkgns = new RenderPkgNamespaces(2);
345   }
346   return pkgns;
347 }
348 
349 
350 /*
351  * This method takes a type code of groups package and returns a string representing
352  * the code.
353  */
354 const char*
getStringFromTypeCode(int typeCode) const355 RenderExtension::getStringFromTypeCode(int typeCode) const
356 {
357   int min = SBML_RENDER_COLORDEFINITION;
358   int max = SBML_RENDER_DEFAULTS;
359 
360   if ( typeCode < min || typeCode > max)
361   {
362     return "(Unknown SBML Render Type)";
363   }
364 
365   return SBML_RENDER_TYPECODE_STRINGS[typeCode - min];
366 }
367 
368 
369 
370 /** @cond doxygenLibsbmlInternal */
371 
372 /*
373  * Returns the entry in the error table at this index.
374  */
375 packageErrorTableEntry
getErrorTable(unsigned int index) const376 RenderExtension::getErrorTable(unsigned int index) const
377 {
378   return renderErrorTable[index];
379 }
380 
381 /** @endcond */
382 
383 
384 
385 /** @cond doxygenLibsbmlInternal */
386 
387 /*
388  * Return the index in the error table with the given errorId.
389  */
390 unsigned int
getErrorTableIndex(unsigned int errorId) const391 RenderExtension::getErrorTableIndex(unsigned int errorId) const
392 {
393   unsigned int tableSize =
394     sizeof(renderErrorTable)/sizeof(renderErrorTable[0]);
395   unsigned int index = 0;
396 
397   for (unsigned int i = 0; i < tableSize; i++)
398   {
399     if (errorId == renderErrorTable[i].code)
400     {
401       index = i;
402       break;
403     }
404   }
405 
406   return index;
407 }
408 
409 /** @endcond */
410 
411 
412 
413 /** @cond doxygenLibsbmlInternal */
414 
415 /*
416  * Returns the offset for the errorId range for the "render" package.
417  */
418 unsigned int
getErrorIdOffset() const419 RenderExtension::getErrorIdOffset() const
420 {
421   return 1300000;
422 }
423 
424 /** @endcond */
425 
426 /** @cond doxygenLibsbmlInternal */
427 /*
428  *
429  * Initialization function of groups extension module which is automatically invoked
430  * by SBMLExtensionRegister class before main() function invoked.
431  *
432  */
433 void
init()434 RenderExtension::init()
435 {
436   //-------------------------------------------------------------------------
437   //
438   // 1. Checks if the groups pacakge has already been registered.
439   //
440   //-------------------------------------------------------------------------
441 
442   if (SBMLExtensionRegistry::getInstance().isRegistered(getPackageName()))
443   {
444     // do nothing;
445     return;
446   }
447 
448   //-------------------------------------------------------------------------
449   //
450   // 2. Creates an SBMLExtension derived object.
451   //
452   //-------------------------------------------------------------------------
453 
454   RenderExtension renderExtension;
455 
456   //-------------------------------------------------------------------------------------
457   //
458   // 3. Creates SBasePluginCreatorBase derived objects required for this
459   //    extension. The derived classes can be instantiated by using the following
460   //     template class.
461   //
462   //    temaplate<class SBasePluginType> class SBasePluginCreator
463   //
464   //    The constructor of the creator class has two arguments:
465   //
466   //        (1) SBaseExtensionPoint : extension point to which the plugin object connected
467   //        (2) std::vector<std::string> : a std::vector object that contains a list of URI
468   //                                       (package versions) supported by the plugin object.
469   //
470   //    For example, two plugin objects (plugged in SBMLDocument and Model elements) are
471   //    required for the groups extension.
472   //
473   //    Since only 'required' attribute is used in SBMLDocument by the groups package, existing
474   //    SBMLDocumentPluginNotRequired class can be used as-is for the plugin.
475   //
476   //    Since the lists of supported package versions (currently only L3V1-groups-V1 supported )
477   //    are equal in the both plugin objects, the same vector object is given to each
478   //    constructor.
479   //
480   //---------------------------------------------------------------------------------------
481 
482   std::vector<std::string> packageURIs;
483   packageURIs.push_back(getXmlnsL3V1V1());
484   packageURIs.push_back(getXmlnsL2());
485 
486   //
487   // LayoutSpeciesReferencePlugin is used only for SBML Level 2
488   //
489   std::vector<std::string> L2packageURI;
490   L2packageURI.push_back(getXmlnsL2());
491 
492   SBaseExtensionPoint sbmldocExtPoint("core",SBML_DOCUMENT);
493   SBaseExtensionPoint layoutExtPoint("layout",SBML_LAYOUT_LAYOUT);
494   SBaseExtensionPoint layoutGOExtPoint("layout",SBML_LAYOUT_GRAPHICALOBJECT);
495   SBaseExtensionPoint clayoutExtPoint("core",SBML_LAYOUT_LAYOUT);
496   SBaseExtensionPoint listOfLayoutsExtPoint("layout", SBML_LIST_OF);
497 
498   SBasePluginCreator<RenderSBMLDocumentPlugin, RenderExtension> sbmldocPluginCreator(sbmldocExtPoint,packageURIs);
499   SBasePluginCreator<RenderLayoutPlugin,   RenderExtension> layoutPluginCreator(layoutExtPoint,packageURIs);
500   SBasePluginCreator<RenderLayoutPlugin,   RenderExtension> clayoutPluginCreator(clayoutExtPoint,packageURIs);
501   SBasePluginCreator<RenderListOfLayoutsPlugin,   RenderExtension> lolPluginCreator(listOfLayoutsExtPoint,packageURIs);
502   SBasePluginCreator<RenderGraphicalObjectPlugin,   RenderExtension> goPluginCreator(layoutGOExtPoint,packageURIs);
503 
504   //--------------------------------------------------------------------------------------
505   //
506   // 3. Adds the above SBasePluginCreatorBase derived objects to the SBMLExtension derived object.
507   //
508   //--------------------------------------------------------------------------------------
509 
510   renderExtension.addSBasePluginCreator(&sbmldocPluginCreator);
511   renderExtension.addSBasePluginCreator(&layoutPluginCreator);
512   renderExtension.addSBasePluginCreator(&clayoutPluginCreator);
513   renderExtension.addSBasePluginCreator(&lolPluginCreator);
514   renderExtension.addSBasePluginCreator(&goPluginCreator);
515 
516   //-------------------------------------------------------------------------
517   //
518   // 4. Registers the SBMLExtension derived object to SBMLExtensionRegistry
519   //
520   //-------------------------------------------------------------------------
521 
522   int result = SBMLExtensionRegistry::getInstance().addExtension(&renderExtension);
523 
524   if (result != LIBSBML_OPERATION_SUCCESS)
525   {
526     std::cerr << "[Error] RenderExtension::init() failed." << std::endl;
527   }
528 
529   // add converter to registry;
530   RenderLayoutConverter rlc;
531   SBMLConverterRegistry::getInstance().addConverter(&rlc);
532 }
533 /** @endcond */
534 
535 
536 /*
537  * Removes the L2 Namespace from a document.
538  *
539  * This method should be overridden by all extensions that want to serialize
540  * to an L2 annotation.
541  */
removeL2Namespaces(XMLNamespaces * xmlns) const542 void RenderExtension::removeL2Namespaces(XMLNamespaces* xmlns)  const
543 {
544   for (int n = 0; n < xmlns->getNumNamespaces(); n++)
545   {
546     if (xmlns->getURI(n) == RenderExtension::getXmlnsL2())
547     {
548       xmlns->remove(n);
549     }
550   }
551 }
552 
553 /*
554  * adds the L2 Namespace
555  *
556  * This method should be overridden by all extensions that want to serialize
557  * to an L2 annotation.
558  */
addL2Namespaces(XMLNamespaces * xmlns) const559 void RenderExtension::addL2Namespaces(XMLNamespaces* xmlns)  const
560 {
561   if (!xmlns->containsUri( RenderExtension::getXmlnsL2()))
562     xmlns->add(RenderExtension::getXmlnsL2(), "render");
563 }
564 
565 /*
566  * Adds the L2 Namespace to the document and enables the extension.
567  *
568  * If the extension supports serialization to SBML L2 Annotations, this
569  * method should be overrridden, so it will be activated.
570  */
enableL2NamespaceForDocument(SBMLDocument * doc) const571 void RenderExtension::enableL2NamespaceForDocument(SBMLDocument* doc)  const
572 {
573   if (doc->getLevel() == 2)
574   {
575     doc->enablePackage(RenderExtension::getXmlnsL2(),"render", true);
576   }
577 }
578 
579 bool
isInUse(SBMLDocument * doc) const580 RenderExtension::isInUse(SBMLDocument *doc) const
581 {
582 
583   if (doc == NULL || doc->getModel() == NULL) return false;
584   LayoutModelPlugin* plugin = (LayoutModelPlugin*)doc->getModel()->getPlugin("layout");
585   if (plugin == NULL || plugin->getNumLayouts() == 0) return false;
586 
587   RenderListOfLayoutsPlugin* lolPlugin = (RenderListOfLayoutsPlugin*) plugin->getListOfLayouts()->getPlugin("render");
588   if (lolPlugin != NULL && lolPlugin->getNumGlobalRenderInformationObjects() > 0) return true;
589 
590   for(int i = 0; i < plugin->getNumLayouts(); i++)
591   {
592     Layout* layout = plugin->getLayout(i);
593     RenderLayoutPlugin* rPlugin = (RenderLayoutPlugin*)layout->getPlugin("render");
594     if (rPlugin != NULL && rPlugin->getNumLocalRenderInformationObjects() > 0) return true;
595   }
596 
597   return false;
598 }
599 
600 
601 #endif  /* __cplusplus */
602 
603 
604 //static
605 //const char* SBML_STYLE_TYPE_STRINGS[] =
606 //{
607 //  "COMPARTMENTGLYPH"
608 //, "SPECIESGLYPH"
609 //, "REACTIONGLYPH"
610 //, "SPECIESREFERENCEGLYPH"
611 //, "TEXTGLYPH"
612 //, "GENERALGLYPH"
613 //, "GRAPHICALOBJECT"
614 //, "ANY"
615 //, "invalid StyleType"
616 //};
617 //
618 //
619 ///*
620 // * Returns the string version of the provided #StyleType_t enumeration.
621 // */
622 //LIBSBML_EXTERN
623 //const char*
624 //StyleType_toString(StyleType_t st)
625 //{
626 //  int min = STYLE_TYPE_COMPARTMENTGLYPH;
627 //  int max = STYLE_TYPE_INVALID;
628 //
629 //  if (st < min || st > max)
630 //  {
631 //    return "(Unknown StyleType value)";
632 //  }
633 //
634 //  return SBML_STYLE_TYPE_STRINGS[st - min];
635 //}
636 //
637 //
638 ///*
639 // * Returns the #StyleType_t enumeration corresponding to the given string or
640 // * @sbmlconstant{STYLE_TYPE_INVALID, StyleType_t} if there is no such match.
641 // */
642 //LIBSBML_EXTERN
643 //StyleType_t
644 //StyleType_fromString(const char* code)
645 //{
646 //  static int size =
647 //    sizeof(SBML_STYLE_TYPE_STRINGS)/sizeof(SBML_STYLE_TYPE_STRINGS[0]);
648 //  std::string type(code);
649 //
650 //  for (int i = 0; i < size; i++)
651 //  {
652 //    if (type == SBML_STYLE_TYPE_STRINGS[i])
653 //    {
654 //      return (StyleType_t)(i);
655 //    }
656 //  }
657 //
658 //  return STYLE_TYPE_INVALID;
659 //}
660 //
661 //
662 ///*
663 // * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
664 // * given #StyleType_t is valid.
665 // */
666 //LIBSBML_EXTERN
667 //int
668 //StyleType_isValid(StyleType_t st)
669 //{
670 //  int min = STYLE_TYPE_COMPARTMENTGLYPH;
671 //  int max = STYLE_TYPE_INVALID;
672 //
673 //  if (st < min || st >= max)
674 //  {
675 //    return 0;
676 //  }
677 //  else
678 //  {
679 //    return 1;
680 //  }
681 //}
682 //
683 //
684 ///*
685 // * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
686 // * given string is a valid #StyleType_t.
687 // */
688 //LIBSBML_EXTERN
689 //int
690 //StyleType_isValidString(const char* code)
691 //{
692 //  return StyleType_isValid(StyleType_fromString(code));
693 //}
694 //
695 //
696 static
697 const char* SBML_GRADIENT_SPREAD_METHOD_STRINGS[] =
698 {
699   "pad"
700 , "reflect"
701 , "repeat"
702 , "invalid"
703 };
704 
705 
706 /*
707  * Returns the string version of the provided #GradientSpreadMethod_t
708  * enumeration.
709  */
710 LIBSBML_EXTERN
711 const char*
GradientSpreadMethod_toString(GradientSpreadMethod_t gsm)712 GradientSpreadMethod_toString(GradientSpreadMethod_t gsm)
713 {
714   int min = GRADIENT_SPREADMETHOD_PAD;
715   int max = GRADIENT_SPREAD_METHOD_INVALID;
716 
717   if (gsm < min || gsm > max)
718   {
719     return "(Unknown GradientSpreadMethod value)";
720   }
721 
722   return SBML_GRADIENT_SPREAD_METHOD_STRINGS[gsm - min];
723 }
724 
725 
726 /*
727  * Returns the #GradientSpreadMethod_t enumeration corresponding to the given
728  * string or @sbmlconstant{GRADIENT_SPREAD_METHOD_INVALID,
729  * GradientSpreadMethod_t} if there is no such match.
730  */
731 LIBSBML_EXTERN
732 GradientSpreadMethod_t
GradientSpreadMethod_fromString(const char * code)733 GradientSpreadMethod_fromString(const char* code)
734 {
735   static int size =
736     sizeof(SBML_GRADIENT_SPREAD_METHOD_STRINGS)/sizeof(SBML_GRADIENT_SPREAD_METHOD_STRINGS[0]);
737   std::string type(code);
738 
739   for (int i = 0; i < size; i++)
740   {
741     if (type == SBML_GRADIENT_SPREAD_METHOD_STRINGS[i])
742     {
743       return (GradientSpreadMethod_t)(i);
744     }
745   }
746 
747   return GRADIENT_SPREAD_METHOD_INVALID;
748 }
749 
750 
751 /*
752  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
753  * given #GradientSpreadMethod_t is valid.
754  */
755 LIBSBML_EXTERN
756 int
GradientSpreadMethod_isValid(GradientSpreadMethod_t gsm)757 GradientSpreadMethod_isValid(GradientSpreadMethod_t gsm)
758 {
759   int min = GRADIENT_SPREADMETHOD_PAD;
760   int max = GRADIENT_SPREAD_METHOD_INVALID;
761 
762   if (gsm < min || gsm >= max)
763   {
764     return 0;
765   }
766   else
767   {
768     return 1;
769   }
770 }
771 
772 
773 /*
774  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
775  * given string is a valid #GradientSpreadMethod_t.
776  */
777 LIBSBML_EXTERN
778 int
GradientSpreadMethod_isValidString(const char * code)779 GradientSpreadMethod_isValidString(const char* code)
780 {
781   return GradientSpreadMethod_isValid(GradientSpreadMethod_fromString(code));
782 }
783 
784 
785 static
786 const char* SBML_FILL_RULE_STRINGS[] =
787 {
788   "unset"
789 , "nonzero"
790 , "evenodd"
791 , "inherit"
792 , "invalid FillRule"
793 };
794 
795 
796 /*
797  * Returns the string version of the provided #FillRule_t enumeration.
798  */
799 LIBSBML_EXTERN
800 const char*
FillRule_toString(FillRule_t fr)801 FillRule_toString(FillRule_t fr)
802 {
803   int min = FILL_RULE_UNSET;
804   int max = FILL_RULE_INVALID;
805 
806   if (fr < min || fr > max)
807   {
808     return "(Unknown FillRule value)";
809   }
810 
811   return SBML_FILL_RULE_STRINGS[fr - min];
812 }
813 
814 
815 /*
816  * Returns the #FillRule_t enumeration corresponding to the given string or
817  * @sbmlconstant{FILL_RULE_INVALID, FillRule_t} if there is no such match.
818  */
819 LIBSBML_EXTERN
820 FillRule_t
FillRule_fromString(const char * code)821 FillRule_fromString(const char* code)
822 {
823   static int size =
824     sizeof(SBML_FILL_RULE_STRINGS)/sizeof(SBML_FILL_RULE_STRINGS[0]);
825   std::string type(code);
826 
827   for (int i = 0; i < size; i++)
828   {
829     if (type == SBML_FILL_RULE_STRINGS[i])
830     {
831       return (FillRule_t)(i);
832     }
833   }
834 
835   return FILL_RULE_INVALID;
836 }
837 
838 
839 /*
840  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
841  * given #FillRule_t is valid.
842  */
843 LIBSBML_EXTERN
844 int
FillRule_isValid(FillRule_t fr)845 FillRule_isValid(FillRule_t fr)
846 {
847   int min = FILL_RULE_NONZERO;
848   int max = FILL_RULE_INVALID;
849 
850   if (fr < min || fr >= max)
851   {
852     return 0;
853   }
854   else
855   {
856     return 1;
857   }
858 }
859 
860 
861 /*
862  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
863  * given string is a valid #FillRule_t.
864  */
865 LIBSBML_EXTERN
866 int
FillRule_isValidString(const char * code)867 FillRule_isValidString(const char* code)
868 {
869   return FillRule_isValid(FillRule_fromString(code));
870 }
871 
872 
873 static
874 const char* SBML_FONT_FAMILY_STRINGS[] =
875 {
876   "serif"
877 , "sans-serif"
878 , "monospace"
879 , "invalid FontFamily"
880 };
881 
882 
883 /*
884  * Returns the string version of the provided #FontFamily_t enumeration.
885  */
886 LIBSBML_EXTERN
887 const char*
FontFamily_toString(FontFamily_t ff)888 FontFamily_toString(FontFamily_t ff)
889 {
890   int min = FONT_FAMILY_SERIF;
891   int max = FONT_FAMILY_INVALID;
892 
893   if (ff < min || ff > max)
894   {
895     return "(Unknown FontFamily value)";
896   }
897 
898   return SBML_FONT_FAMILY_STRINGS[ff - min];
899 }
900 
901 
902 /*
903  * Returns the #FontFamily_t enumeration corresponding to the given string or
904  * @sbmlconstant{FONT_FAMILY_INVALID, FontFamily_t} if there is no such match.
905  */
906 LIBSBML_EXTERN
907 FontFamily_t
FontFamily_fromString(const char * code)908 FontFamily_fromString(const char* code)
909 {
910   static int size =
911     sizeof(SBML_FONT_FAMILY_STRINGS)/sizeof(SBML_FONT_FAMILY_STRINGS[0]);
912   std::string type(code);
913 
914   for (int i = 0; i < size; i++)
915   {
916     if (type == SBML_FONT_FAMILY_STRINGS[i])
917     {
918       return (FontFamily_t)(i);
919     }
920   }
921 
922   return FONT_FAMILY_INVALID;
923 }
924 
925 
926 /*
927  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
928  * given #FontFamily_t is valid.
929  */
930 LIBSBML_EXTERN
931 int
FontFamily_isValid(FontFamily_t ff)932 FontFamily_isValid(FontFamily_t ff)
933 {
934   int min = FONT_FAMILY_SERIF;
935   int max = FONT_FAMILY_INVALID;
936 
937   if (ff < min || ff >= max)
938   {
939     return 0;
940   }
941   else
942   {
943     return 1;
944   }
945 }
946 
947 
948 /*
949  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
950  * given string is a valid #FontFamily_t.
951  */
952 LIBSBML_EXTERN
953 int
FontFamily_isValidString(const char * code)954 FontFamily_isValidString(const char* code)
955 {
956   return FontFamily_isValid(FontFamily_fromString(code));
957 }
958 
959 
960 static
961 const char* SBML_FONT_WEIGHT_STRINGS[] =
962 {
963   "unset"
964 , "normal"
965 , "bold"
966 , "invalid FontWeight"
967 };
968 
969 
970 /*
971  * Returns the string version of the provided #FontWeight_t enumeration.
972  */
973 LIBSBML_EXTERN
974 const char*
FontWeight_toString(FontWeight_t fw)975 FontWeight_toString(FontWeight_t fw)
976 {
977   int min = FONT_WEIGHT_UNSET;
978   int max = FONT_WEIGHT_INVALID;
979 
980   if (fw < min || fw > max)
981   {
982     return "(Unknown FontWeight value)";
983   }
984 
985   return SBML_FONT_WEIGHT_STRINGS[fw - min];
986 }
987 
988 
989 /*
990  * Returns the #FontWeight_t enumeration corresponding to the given string or
991  * @sbmlconstant{FONT_WEIGHT_INVALID, FontWeight_t} if there is no such match.
992  */
993 LIBSBML_EXTERN
994 FontWeight_t
FontWeight_fromString(const char * code)995 FontWeight_fromString(const char* code)
996 {
997   static int size =
998     sizeof(SBML_FONT_WEIGHT_STRINGS)/sizeof(SBML_FONT_WEIGHT_STRINGS[0]);
999   std::string type(code);
1000 
1001   for (int i = 0; i < size; i++)
1002   {
1003     if (type == SBML_FONT_WEIGHT_STRINGS[i])
1004     {
1005       return (FontWeight_t)(i);
1006     }
1007   }
1008 
1009   return FONT_WEIGHT_INVALID;
1010 }
1011 
1012 
1013 /*
1014  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
1015  * given #FontWeight_t is valid.
1016  */
1017 LIBSBML_EXTERN
1018 int
FontWeight_isValid(FontWeight_t fw)1019 FontWeight_isValid(FontWeight_t fw)
1020 {
1021   int min = FONT_WEIGHT_NORMAL;
1022   int max = FONT_WEIGHT_INVALID;
1023 
1024   if (fw < min || fw >= max)
1025   {
1026     return 0;
1027   }
1028   else
1029   {
1030     return 1;
1031   }
1032 }
1033 
1034 
1035 /*
1036  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
1037  * given string is a valid #FontWeight_t.
1038  */
1039 LIBSBML_EXTERN
1040 int
FontWeight_isValidString(const char * code)1041 FontWeight_isValidString(const char* code)
1042 {
1043   return FontWeight_isValid(FontWeight_fromString(code));
1044 }
1045 
1046 
1047 static
1048 const char* SBML_FONT_STYLE_STRINGS[] =
1049 {
1050   "unset"
1051 , "normal"
1052 ,  "italic"
1053 , "invalid FontStyle"
1054 };
1055 
1056 
1057 /*
1058  * Returns the string version of the provided #FontStyle_t enumeration.
1059  */
1060 LIBSBML_EXTERN
1061 const char*
FontStyle_toString(FontStyle_t fs)1062 FontStyle_toString(FontStyle_t fs)
1063 {
1064   int min = FONT_STYLE_UNSET;
1065   int max = FONT_STYLE_INVALID;
1066 
1067   if (fs < min || fs > max)
1068   {
1069     return "(Unknown FontStyle value)";
1070   }
1071 
1072   return SBML_FONT_STYLE_STRINGS[fs - min];
1073 }
1074 
1075 
1076 /*
1077  * Returns the #FontStyle_t enumeration corresponding to the given string or
1078  * @sbmlconstant{FONT_STYLE_INVALID, FontStyle_t} if there is no such match.
1079  */
1080 LIBSBML_EXTERN
1081 FontStyle_t
FontStyle_fromString(const char * code)1082 FontStyle_fromString(const char* code)
1083 {
1084   static int size =
1085     sizeof(SBML_FONT_STYLE_STRINGS)/sizeof(SBML_FONT_STYLE_STRINGS[0]);
1086   std::string type(code);
1087 
1088   for (int i = 0; i < size; i++)
1089   {
1090     if (type == SBML_FONT_STYLE_STRINGS[i])
1091     {
1092       return (FontStyle_t)(i);
1093     }
1094   }
1095 
1096   return FONT_STYLE_INVALID;
1097 }
1098 
1099 
1100 /*
1101  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
1102  * given #FontStyle_t is valid.
1103  */
1104 LIBSBML_EXTERN
1105 int
FontStyle_isValid(FontStyle_t fs)1106 FontStyle_isValid(FontStyle_t fs)
1107 {
1108   int min = FONT_STYLE_NORMAL;
1109   int max = FONT_STYLE_INVALID;
1110 
1111   if (fs < min || fs >= max)
1112   {
1113     return 0;
1114   }
1115   else
1116   {
1117     return 1;
1118   }
1119 }
1120 
1121 
1122 /*
1123  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
1124  * given string is a valid #FontStyle_t.
1125  */
1126 LIBSBML_EXTERN
1127 int
FontStyle_isValidString(const char * code)1128 FontStyle_isValidString(const char* code)
1129 {
1130   return FontStyle_isValid(FontStyle_fromString(code));
1131 }
1132 
1133 
1134 static
1135 const char* SBML_V_TEXT_ANCHOR_STRINGS[] =
1136 {
1137   "unset"
1138 , "top"
1139 , "middle"
1140 , "bottom"
1141 , "baseline"
1142 , "invalid VTextAnchor"
1143 };
1144 
1145 
1146 /*
1147  * Returns the string version of the provided #VTextAnchor_t enumeration.
1148  */
1149 LIBSBML_EXTERN
1150 const char*
VTextAnchor_toString(VTextAnchor_t vta)1151 VTextAnchor_toString(VTextAnchor_t vta)
1152 {
1153   int min = V_TEXTANCHOR_UNSET;
1154   int max = V_TEXTANCHOR_INVALID;
1155 
1156   if (vta < min || vta > max)
1157   {
1158     return "(Unknown VTextAnchor value)";
1159   }
1160 
1161   return SBML_V_TEXT_ANCHOR_STRINGS[vta - min];
1162 }
1163 
1164 
1165 /*
1166  * Returns the #VTextAnchor_t enumeration corresponding to the given string or
1167  * @sbmlconstant{V_TEXTANCHOR_INVALID, VTextAnchor_t} if there is no
1168  * such match.
1169  */
1170 LIBSBML_EXTERN
1171 VTextAnchor_t
VTextAnchor_fromString(const char * code)1172 VTextAnchor_fromString(const char* code)
1173 {
1174   static int size =
1175     sizeof(SBML_V_TEXT_ANCHOR_STRINGS)/sizeof(SBML_V_TEXT_ANCHOR_STRINGS[0]);
1176   std::string type(code);
1177 
1178   for (int i = 0; i < size; i++)
1179   {
1180     if (type == SBML_V_TEXT_ANCHOR_STRINGS[i])
1181     {
1182       return (VTextAnchor_t)(i);
1183     }
1184   }
1185 
1186   return V_TEXTANCHOR_INVALID;
1187 }
1188 
1189 
1190 /*
1191  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
1192  * given #VTextAnchor_t is valid.
1193  */
1194 LIBSBML_EXTERN
1195 int
VTextAnchor_isValid(VTextAnchor_t vta)1196 VTextAnchor_isValid(VTextAnchor_t vta)
1197 {
1198   int min = V_TEXTANCHOR_TOP;
1199   int max = V_TEXTANCHOR_INVALID;
1200 
1201   if (vta < min || vta >= max)
1202   {
1203     return 0;
1204   }
1205   else
1206   {
1207     return 1;
1208   }
1209 }
1210 
1211 
1212 /*
1213  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
1214  * given string is a valid #VTextAnchor_t.
1215  */
1216 LIBSBML_EXTERN
1217 int
VTextAnchor_isValidString(const char * code)1218 VTextAnchor_isValidString(const char* code)
1219 {
1220   return VTextAnchor_isValid(VTextAnchor_fromString(code));
1221 }
1222 
1223 
1224 static
1225 const char* SBML_H_TEXT_ANCHOR_STRINGS[] =
1226 {
1227   "unset"
1228 , "start"
1229 , "middle"
1230 , "end"
1231 , "invalid HTextAnchor"
1232 };
1233 
1234 
1235 /*
1236  * Returns the string version of the provided #HTextAnchor_t enumeration.
1237  */
1238 LIBSBML_EXTERN
1239 const char*
HTextAnchor_toString(HTextAnchor_t hta)1240 HTextAnchor_toString(HTextAnchor_t hta)
1241 {
1242   int min = H_TEXTANCHOR_UNSET;
1243   int max = H_TEXTANCHOR_INVALID;
1244 
1245   if (hta < min || hta > max)
1246   {
1247     return "(Unknown HTextAnchor value)";
1248   }
1249 
1250   return SBML_H_TEXT_ANCHOR_STRINGS[hta - min];
1251 }
1252 
1253 
1254 /*
1255  * Returns the #HTextAnchor_t enumeration corresponding to the given string or
1256  * @sbmlconstant{H_TEXTANCHOR_INVALID, HTextAnchor_t} if there is no such
1257  * match.
1258  */
1259 LIBSBML_EXTERN
1260 HTextAnchor_t
HTextAnchor_fromString(const char * code)1261 HTextAnchor_fromString(const char* code)
1262 {
1263   static int size =
1264     sizeof(SBML_H_TEXT_ANCHOR_STRINGS)/sizeof(SBML_H_TEXT_ANCHOR_STRINGS[0]);
1265   std::string type(code);
1266 
1267   for (int i = 0; i < size; i++)
1268   {
1269     if (type == SBML_H_TEXT_ANCHOR_STRINGS[i])
1270     {
1271       return (HTextAnchor_t)(i);
1272     }
1273   }
1274 
1275   return H_TEXTANCHOR_INVALID;
1276 }
1277 
1278 
1279 /*
1280  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
1281  * given #HTextAnchor_t is valid.
1282  */
1283 LIBSBML_EXTERN
1284 int
HTextAnchor_isValid(HTextAnchor_t hta)1285 HTextAnchor_isValid(HTextAnchor_t hta)
1286 {
1287   int min = H_TEXTANCHOR_START;
1288   int max = H_TEXTANCHOR_INVALID;
1289 
1290   if (hta < min || hta >= max)
1291   {
1292     return 0;
1293   }
1294   else
1295   {
1296     return 1;
1297   }
1298 }
1299 
1300 
1301 /*
1302  * Predicate returning @c 1 (true) or @c 0 (false) depending on whether the
1303  * given string is a valid #HTextAnchor_t.
1304  */
1305 LIBSBML_EXTERN
1306 int
HTextAnchor_isValidString(const char * code)1307 HTextAnchor_isValidString(const char* code)
1308 {
1309   return HTextAnchor_isValid(HTextAnchor_fromString(code));
1310 }
1311 
1312 
1313 
1314 
1315 LIBSBML_CPP_NAMESPACE_END
1316