96 |
docutils.parsers.rst.directives._directives['uml-refer'] = uml_refer_directive |
docutils.parsers.rst.directives._directives['uml-refer'] = uml_refer_directive |
97 |
|
|
98 |
def create_diagram(diagram): |
def create_diagram(diagram): |
99 |
umltool.run(diagram) |
return (umltool.run(diagram)) |
100 |
|
|
101 |
|
def create_diagram(diagram_orig, diagram_copy="", zoom=100): |
102 |
|
return (umltool.run(diagram_orig, diagram_copy, zoom)) |
103 |
|
|
104 |
def embed_diagram(path): |
def embed_diagram(path): |
105 |
if not umltool.settings.has_key('to_root'): |
if not umltool.settings.has_key('to_root'): |
123 |
assert (os.path.isfile(umltool.settings['tmpdir']+"/"+prefix+".uml")\ |
assert (os.path.isfile(umltool.settings['tmpdir']+"/"+prefix+".uml")\ |
124 |
and os.path.isfile(umltool.settings['tmpdir']+"/"+prefix+".mp")),\ |
and os.path.isfile(umltool.settings['tmpdir']+"/"+prefix+".mp")),\ |
125 |
"file "+ prefix+".uml or "+prefix+".mp not found" |
"file "+ prefix+".uml or "+prefix+".mp not found" |
126 |
print "Embedding %s into %s" % (name, path) |
print "Embedding %s into %s" % (prefix, path) |
127 |
create_diagram(prefix) |
|
128 |
|
implicit_targets = create_diagram(prefix) |
129 |
|
for target in implicit_targets: |
130 |
|
embed_implicit(name, target) |
131 |
|
|
132 |
assert (os.path.isfile(umltool.settings['tmpdir']+"/"+name+".gen.html")\ |
assert (os.path.isfile(umltool.settings['tmpdir']+"/"+name+".gen.html")\ |
133 |
and os.path.isfile(umltool.settings['tmpdir']+"/"+name+".gen.png")),\ |
and os.path.isfile(umltool.settings['tmpdir']+"/"+name+".gen.png")),\ |
134 |
"file "+name+".gen.html or "+name+".gen.png not found" |
"file "+name+".gen.html or "+name+".gen.png not found" |
146 |
out.write(html) |
out.write(html) |
147 |
out.close() |
out.close() |
148 |
|
|
149 |
|
def embed_implicit(name, path): |
150 |
|
"""Terrible kludge to embed named diagram into path document |
151 |
|
with correct imagemap.""" |
152 |
|
tmp = umltool.settings.copy() |
153 |
|
umltool.set_to_root(path) |
154 |
|
|
155 |
|
#the second pass - adds uml into html |
156 |
|
if path.endswith(".rst"): path = path[0:len(path)-4] |
157 |
|
if os.path.isfile(path+".html"): |
158 |
|
html = open(path+".html").read() |
159 |
|
insert = html.upper().find("</H1>") |
160 |
|
if insert == -1: insert = html.upper().find("</H2>") |
161 |
|
|
162 |
|
#the same diagram is written only once |
163 |
|
if html.find("id=\""+name+"\"") == -1 and insert != -1: |
164 |
|
out = open(path+".html", "w") |
165 |
|
out.write(html[0:insert+5]); |
166 |
|
|
167 |
|
#This should work also with non-generated UML-diagrams. Checks first |
168 |
|
#for generated and then if non-generated diagram exists. |
169 |
|
if (os.path.isfile(umltool.settings['tmpdir']+"/"+name+".gen.uml")): |
170 |
|
old_prefix = name + ".gen" |
171 |
|
else: old_prefix = name |
172 |
|
|
173 |
|
print "Embedding %s into %s" % (name, path) |
174 |
|
|
175 |
|
new_prefix = name+"_"+path.replace("/","_") |
176 |
|
create_diagram(old_prefix, new_prefix, 100) |
177 |
|
|
178 |
|
#Cut&Pastes imagemap into html |
179 |
|
imgmap = open(umltool.settings['tmpdir']+"/"+new_prefix+".gen.html").read() |
180 |
|
out.write("<map id=\""+name+"\" name=\""+name+"\">\n") |
181 |
|
out.write(imgmap[imgmap.find('>',imgmap.find('<map'))+1:\ |
182 |
|
imgmap.find('</map>')]) |
183 |
|
out.write("</map>\n") |
184 |
|
out.write("<img "\ |
185 |
|
+"src=\""+umltool.settings['to_tmpdir']+"/"\ |
186 |
|
+new_prefix+".gen.png"\ |
187 |
|
+"\" usemap=\"#"+name+"\" alt=\""+name+"\" />") |
188 |
|
|
189 |
|
html = html[insert+5:len(html)] |
190 |
|
out.write(html) |
191 |
|
out.close() |
192 |
|
|
193 |
|
umltool.settings = tmp |