File: printRenderInformation.py

package info (click to toggle)
libsbml 5.17.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 156,336 kB
  • sloc: cpp: 1,012,766; xml: 314,374; cs: 58,129; ansic: 54,053; python: 27,299; java: 27,152; makefile: 9,721; perl: 9,039; sh: 8,777; ruby: 4,760; php: 202; csh: 3
file content (114 lines) | stat: -rw-r--r-- 4,405 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 
# @file    printRenderInformation.py
# @brief   prints an overview of the render information in the given SBML file
# @author  Frank Bergmann
# 
# This file is part of libSBML.  Please visit http:#sbml.org for more
# information about SBML, and the latest version of libSBML.
# 
import sys
import os.path
from libsbml import *


def toString(vec):
    return str(vec.getAbsoluteValue()) + " + " + str(vec.getRelativeValue()) + "%"

def main (args):
  """
    Usage:  printRenderInformation <input file>
            prints a summary of the render information object.
  """
  
  if (len(args) != 2):
        print(main.__doc__)
        return 1


  inputFile = args[1];

  doc = readSBMLFromFile(inputFile);
  numErrors = doc.getNumErrors();

  if (numErrors > 0):
      print("Encountered errors while reading the file. ");
      print("Please correct the following errors and try again.");
      doc.printErrors();
      return 2;

  model = doc.getModel();

  plugin = model.getPlugin("layout");

  if (plugin == None or plugin.getNumLayouts() == 0):
      print("The loaded model contains no layout information, please add these first.");
      return 3;

  lolPlugin = plugin.getListOfLayouts().getPlugin("render");
  if (lolPlugin != None and lolPlugin.getNumGlobalRenderInformationObjects() > 0):
      print("The loaded model contains global Render information: ");

      for  i in range ( 0, lolPlugin.getNumGlobalRenderInformationObjects()):
          info = lolPlugin.getRenderInformation(i);

          print("Id: " + info.getId());
          print("Name: " + info.getName());
          print("Program Name: " + info.getProgramName());
          print("Program Version: " + info.getProgramVersion());
          print("Background color: " + info.getBackgroundColor());

          print("Color Definitions:");
          for  j in range ( 0, info.getNumColorDefinitions()):
              color = info.getColorDefinition(j);			  
              print("\tcolor: " + str(j) +
                                " id: " + color.getId() +
                                " color: " + color.createValueString());

          print("GradientDefinitions: ");
          for j in range (0, info.getNumGradientDefinitions()):
              grad = info.getGradientDefinition(j);

              if (grad.getElementName() == "linearGradient"):
                  print("\tLinear Gradient: " + grad.getId()
                                    + " start: " + toString(grad.getXPoint1()) + ", " +
                                    toString(grad.getYPoint1())
                                    + " end: " + toString(grad.getXPoint2()) + ", " +
                                    toString(grad.getYPoint2())
                      );
              else:
                  print("\tRadial Gradient: " + grad.getId()
                                    + " center: " + toString(grad.getCenterX()) + ", " +
                                    toString(grad.getCenterY())
                                    + " focal: " + toString(grad.getFocalPointX()) + ", " +
                                    toString(grad.getFocalPointY())
                      );

              for k in range (0, grad.getNumGradientStops()):
                  stop = grad.getGradientStop(k);
                  print("\t\tstop " + str(k) + " id: " + stop.getId() + " stop-color: " +
                                    stop.getStopColor());

          # similarly for the remaining elements 
          print("\tNumber of Line Endings: " + str(info.getNumLineEndings()));

          # and finally the styles

          for j in range (0, info.getNumStyles()):
              style = info.getStyle(j);

              print("\tstyle " + str(j) + " id: " + style.getId() + " applies to: ");
              print("\t\troles:" + style.createRoleString() +
                                " types: " + style.createTypeString());

  # add render information to the first layout
  layout = plugin.getLayout(0);

  rPlugin = layout.getPlugin("render");
  if (rPlugin != None and rPlugin.getNumLocalRenderInformationObjects() > 0):
      print("The loaded model contains local Render information. ");
      # here we would do the same as above for the local render information ...

  return 0;

if __name__ == '__main__':
  main(sys.argv)