-
Notifications
You must be signed in to change notification settings - Fork 5
/
BaseTexFile.py
189 lines (162 loc) · 6.96 KB
/
BaseTexFile.py
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
#!/usr/bin/env python
#
# @file BaseTexFile.py
# @brief base class for all tex files to be generated
# @author Frank Bergmann
# @author Sarah Keating
# @author Matthew S. Gillman
#
# <!--------------------------------------------------------------------------
#
# Copyright (c) 2013-2018 by the California Institute of Technology
# (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
# and the University of Heidelberg (Germany), with support from the National
# Institutes of Health (USA) under grant R01GM070923. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Neither the name of the California Institute of Technology (Caltech), nor
# of the European Bioinformatics Institute (EMBL-EBI), nor of the University
# of Heidelberg, nor the names of any contributors, may be used to endorse
# or promote products derived from this software without specific prior
# written permission.
# ------------------------------------------------------------------------ -->
from ..util import global_variables, strFunctions
from . import BaseFile
class BaseTexFile(BaseFile.BaseFile):
"""Common base class for all LaTeX files"""
def __init__(self, name, extension, object_desc):
"""
Constructor
:param name: name of file (before dot and extension)
:param extension: file extension (without dot, e.g. "tex").
:param object_desc:
"""
BaseFile.BaseFile.__init__(self, name, extension)
# change the comment delimiter and line length
self.comment = "%"
self.line_length = 72
if global_variables.is_sbml:
self.package = object_desc["name"]
self.fullname = object_desc["fullname"]
self.sbml_classes = object_desc["baseElements"]
self.offset = object_desc["offset"]
self.plugins = object_desc["plugins"]
self.enums = object_desc["enums"]
self.level = object_desc["base_level"]
self.version = object_desc["base_version"]
self.pkg_version = object_desc["pkg_version"]
if object_desc["required"]:
self.reqd_status = "true"
else:
self.reqd_status = "false"
else:
self.package = ''
self.fullname = global_variables.package_full_name
self.sbml_classes = object_desc["baseElements"]
self.offset = object_desc["offset"]
self.plugins = []
self.enums = object_desc["enums"]
self.level = object_desc["base_level"]
self.version = object_desc["base_version"]
self.pkg_version = 0
self.reqd_status = "false"
self.prim_class = []
self.start_b = "{"
self.end_b = "}"
# expand the information for the classes
self.fulltexname = strFunctions.texify(self.fullname)
self.upper_package = strFunctions.upper_first(self.package)
self.sort_class_names(self.sbml_classes)
self.sort_attribute_names(self.sbml_classes)
self.sort_enum_names(self.enums)
if global_variables.is_sbml:
self.full_pkg_command = "\\{0}Package".format(self.fulltexname)
else:
self.full_pkg_command = "\\{0}".format(self.fulltexname)
self.brief_pkg_command = "\\{0}".format(self.upper_package)
########################################################################
def sort_class_names(self, classes):
"""
Function to create texnames for classes.
:param classes: list of objects (dictionaries) representing classes.
"""
if classes is not None:
for i in range(0, len(classes)):
name = classes[i]["name"]
texname = strFunctions.texify(name)
classes[i]["texname"] = texname
# hack for render
if name == "Ellipse" or name == "Rectangle":
texname = "Render" + name
classes[i]["texname"] = texname
if name == "RelAbsVector":
self.prim_class.append(classes[i])
@staticmethod
def sort_attribute_names(classes):
"""
Function to create texnames for attributes.
:param classes:
"""
if classes is not None:
for i in range(0, len(classes)):
attribs = classes[i]["attribs"]
BaseTexFile.update_attrib_dicts(attribs)
for i in range(0, len(classes)):
if "lo_attribs" in classes[i]:
lo_attribs = classes[i]["lo_attribs"]
BaseTexFile.update_attrib_dicts(lo_attribs)
@staticmethod
def update_attrib_dicts(my_list):
"""
Update a list of attribute dictionaries.
:param my_list: the list which we update.
"""
for j in range(0, len(my_list)):
if my_list[j]["type"] in ["lo_element", "element", "inline_lo_element"]:
name = my_list[j]["element"]
else:
name = my_list[j]["name"]
texname = strFunctions.texify(name)
my_list[j]["texname"] = texname
@staticmethod
def sort_enum_names(enums):
"""
Function to create texnames for enums
:param enums:
"""
if enums is not None:
for i in range(0, len(enums)):
name = enums[i]["name"]
texname = strFunctions.texify(name)
enums[i]["texname"] = texname
def write_to_do(self, text):
"""
Function to write a to do into text
i.e. \todo{text goes here}
:param text: the text describing the TODO.
"""
self.write_text_line("\\TODO{0}{1}{2}".format(self.start_b, text, self.end_b))
self.skip_line()
def write_text_line(self, line):
"""
Need to overwrite the write_text_line function to not add indents
:param line: the line of text to write
"""
self.write_line_no_indent(line)