File: printRenderInformation.cs

package info (click to toggle)
libsbml 5.20.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 117,108 kB
  • sloc: cpp: 469,781; xml: 364,270; ansic: 54,078; python: 12,540; makefile: 9,757; sh: 9,245; cs: 8,586; java: 8,151; perl: 6,133; ruby: 4,760; javascript: 1,605; php: 202; csh: 3
file content (218 lines) | stat: -rw-r--r-- 8,484 bytes parent folder | download | duplicates (4)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// 
// @file    printRenderInformation.cs
// @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.
// 
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using libsbmlcs;

public class cs_printRenderInformation
{


    public static String toString(RelAbsVector vec)
    {
        return vec.getAbsoluteValue().ToString() + " + " + vec.getRelativeValue().ToString() + "%";
    }

    public static int Main(string[] args)
    {
        if (args.Length != 1)
        {
            Console.WriteLine(" Usage:  printRenderInformation <input file> \n" +
                    "      prints a summary of the render information object.");
            return 1;
        }


        string inputFile = args[0];

        SBMLDocument doc = libsbml.readSBMLFromFile(inputFile);

        Console.WriteLine("Using libSBML: {0} supporting packages for:", libsbml.getLibSBMLDottedVersion());
        for (int i = 0; i < SBMLExtensionRegistry.getNumRegisteredPackages(); ++i)
            Console.WriteLine("\t {0}", SBMLExtensionRegistry.getRegisteredPackageName(i));

        Console.WriteLine("\nThe document is: level {0}, version {1}", doc.getLevel(), doc.getVersion());
        for (int i = 0; i < doc.getNumPlugins(); ++i)
            Console.WriteLine("  doc uses package: {0}", doc.getPlugin(i).getElementNamespace());

        Console.WriteLine("\n");

        long numErrors = doc.getNumErrors(libsbml.LIBSBML_SEV_ERROR);

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

        Model model = doc.getModel();

        LayoutModelPlugin plugin = (LayoutModelPlugin) model.getPlugin("layout");

        if (plugin == null || plugin.getNumLayouts() == 0)
        {
            Console.WriteLine("The loaded model contains no layout information, please add these first.");
            return 3;
        }

        RenderListOfLayoutsPlugin lolPlugin = (RenderListOfLayoutsPlugin)plugin.getListOfLayouts().getPlugin("render");
        if (lolPlugin != null && lolPlugin.getNumGlobalRenderInformationObjects() > 0)
        {
            Console.WriteLine("The loaded model contains global Render information: ");

            for (int i = 0; i < lolPlugin.getNumGlobalRenderInformationObjects(); ++i)
            {
                GlobalRenderInformation info = lolPlugin.getRenderInformation(i);
                print_render_info(info);
            }
        }

        Layout layout = plugin.getLayout(0);

        RenderLayoutPlugin rPlugin = (RenderLayoutPlugin)layout.getPlugin("render");
        if (rPlugin != null && rPlugin.getNumLocalRenderInformationObjects() > 0)
        {
            Console.WriteLine("The loaded model contains local Render information. ");
            // here we would do the same as above for the local render information ...
            for (int i = 0; i < rPlugin.getNumLocalRenderInformationObjects(); ++i)
            {
            LocalRenderInformation info = rPlugin.getRenderInformation(i);
            print_render_info(info);
            }
        }

        return 0;
    }

    public static void print_render_info(GlobalRenderInformation info)
    {
        print_render_info((RenderInformationBase)info);

        // and finally the styles
        Console.WriteLine("\nStyles: ");
        for (int j = 0; j < info.getNumGlobalStyles(); ++j)
        {
            GlobalStyle style = info.getGlobalStyle(j);
            print_style(style, j);
        }
    }

    public static void print_render_info(LocalRenderInformation info)
    {
        print_render_info((RenderInformationBase)info);

        // and finally the styles
        Console.WriteLine("\nStyles: ");
        for (int j = 0; j < info.getNumLocalStyles(); ++j)
        {
            LocalStyle style = info.getLocalStyle(j);
            print_style(style, j);
        }
    }

    public static void print_render_info(RenderInformationBase info)
    {
        if (info.isSetId())
            Console.WriteLine("  Id: " + info.getId());
        if (info.isSetName())
            Console.WriteLine("  Name: " + info.getName());
        if (info.isSetProgramName())
            Console.WriteLine("  Program Name: " + info.getProgramName());
        if (info.isSetProgramVersion())
            Console.WriteLine("  Program Version: " + info.getProgramVersion());
        if (info.isSetBackgroundColor())
            Console.WriteLine("  Background color: " + info.getBackgroundColor());

        Console.WriteLine("\nColor Definitions:");
        for (int j = 0; j < info.getNumColorDefinitions(); ++j)
        {
            ColorDefinition color = info.getColorDefinition(j);
            Console.WriteLine("\tcolor: " + j.ToString() +
                              " id: " + color.getId() +
                              " color: " + color.getValue());
        }

        Console.WriteLine("\nGradientDefinitions: ");
        for (int j = 0; j < info.getNumGradientDefinitions(); ++j)
        {
            GradientBase grad = info.getGradientDefinition(j);

            print_gradient_definition(grad);
        }

        // similarly for the remaining elements 
        Console.WriteLine("\nNumber of Line Endings: {0}", info.getNumLineEndings());
    }

    public static void print_style(Style style, int index)
    {
        Console.WriteLine("\tstyle " + index.ToString() + " id: " + style.getId() + " applies to: ");
        Console.WriteLine("\t\troles:" + style.createRoleString() +
                          " types: " + style.createTypeString());

        if (!style.isSetGroup())
            return;

        RenderGroup group = style.getGroup();
        if (group.isSetStroke())
            Console.WriteLine("\t\tstroke: {0}",group.getStroke());

        if (group.isSetFill())
            Console.WriteLine("\t\tfill: {0}", group.getFill());

        for (int j = 0; j < group.getNumElements(); ++j)
        {
            object element = group.getElement(j);
            if (element is GraphicalPrimitive2D)
                Console.WriteLine("\t\tsub element {0} stroke {1}, fill {2}", ((GraphicalPrimitive2D)element).getElementName(), ((GraphicalPrimitive2D)element).getStroke(), ((GraphicalPrimitive2D)element).getFill());
            else if (element is GraphicalPrimitive1D)
                Console.WriteLine("\t\tsub element {0} stroke {1}", ((GraphicalPrimitive1D)element).getElementName(), ((GraphicalPrimitive1D)element).getStroke());
        }

    }

    public static void print_gradient_definition(GradientBase element)
    {
        if (element is LinearGradient)
        {            
            LinearGradient grad = (LinearGradient)element;
            Console.WriteLine("\tLinear Gradient: " + grad.getId()
                              + " start: " + toString(grad.getXPoint1()) + ", " +
                              toString(grad.getYPoint1())
                              + " end: " + toString(grad.getXPoint2()) + ", " +
                              toString(grad.getYPoint2())
            );
        }
        else if (element is RadialGradient)
        {
            RadialGradient grad = (RadialGradient)element;
            Console.WriteLine("\tRadial Gradient: " + grad.getId()
                              + " center: " + toString(grad.getCenterX()) + ", " +
                              toString(grad.getCenterY())
                              + " focal: " + toString(grad.getFocalPointX()) + ", " +
                              toString(grad.getFocalPointY())
                );
        }

        for (int k = 0; k < element.getNumGradientStops(); ++k)
        {
            GradientStop stop = element.getGradientStop(k);
            if (stop == null)
            {
                continue;
            }
            Console.WriteLine("\t\tstop " + k.ToString() + " id: " + stop.getId() + " stop-color: " +
                              stop.getStopColor());
        }
    }
}