53 |
elif os.path.isfile(slashify(path)+entry): |
elif os.path.isfile(slashify(path)+entry): |
54 |
embed_imagemap(slashify(path)+entry) |
embed_imagemap(slashify(path)+entry) |
55 |
|
|
56 |
|
def embed_javascript(filepath): |
57 |
|
html_file = open(filepath) |
58 |
|
html = html_file.read() |
59 |
|
html_file.close() |
60 |
|
|
61 |
|
if html.find('function setImg') == -1: |
62 |
|
insert = html.upper().find('</HEAD>') |
63 |
|
out = open(filepath, "w") |
64 |
|
out.write(html[:insert]); |
65 |
|
out.write(""" |
66 |
|
<script language="JavaScript"> |
67 |
|
<!-- Begin JavaScript |
68 |
|
function setImg(img_id, img_src, img_usemap) { |
69 |
|
document[img_id].setAttribute("src", img_src); |
70 |
|
document[img_id].setAttribute("usemap", img_usemap); |
71 |
|
} |
72 |
|
// End --> |
73 |
|
</script> |
74 |
|
""") |
75 |
|
out.write(html[insert:]) |
76 |
|
out.close() |
77 |
|
|
78 |
def embed_imagemap(filepath): |
def embed_imagemap(filepath): |
79 |
dbg('Checking %s for imagemapping diagrams' % (filepath)) |
dbg('Checking %s for imagemapping diagrams' % (filepath)) |
80 |
|
|
81 |
config.working_directory = os.path.normpath(os.path.dirname(filepath)) |
config.working_directory = os.path.normpath(os.path.dirname(filepath)) |
82 |
config.input_filename = os.path.basename(filepath) |
config.input_filename = os.path.basename(filepath) |
83 |
config.output_filename = os.path.basename(filepath) |
config.output_filename = os.path.basename(filepath) |
84 |
|
|
85 |
|
embed_javascript(filepath) |
86 |
|
|
87 |
htmlfile = open(filepath) |
htmlfile = open(filepath) |
88 |
html = htmlfile.read() |
html = htmlfile.read() |
89 |
htmlfile.close() |
htmlfile.close() |
90 |
|
|
91 |
insert = html.find('<img _uml="') |
insert = html.find('<img _uml="') |
92 |
while insert > -1: |
while insert > -1: |
93 |
diagram = html[insert+11:html.find('"', insert+11)] |
diagram = html[insert+11:html.find('"', insert+11)] |
105 |
else: |
else: |
106 |
out.close() |
out.close() |
107 |
create_uml(diagram, context) |
create_uml(diagram, context) |
108 |
|
create_uml(diagram, context+'_implicit', scale=0.5) |
109 |
out = open(filepath, "w") |
out = open(filepath, "w") |
110 |
out.write(html[0:insert]); |
out.write(html[0:insert]); |
111 |
dbg_navidoc("Mapping diagram %s within %s" % (diagram, filepath)) |
dbg_navidoc("Mapping diagram %s within %s" % (diagram, filepath)) |
112 |
imgmap = get_imagemap(diagram, context) |
imgmap = get_imagemap(diagram, context) |
113 |
|
imgmap_implicit = get_imagemap(diagram, context+'_implicit', scale=0.5, id_postfix="_implicit") |
114 |
dbg("Diagram %s imagemap: %s" % (diagram, "\n"+str(imgmap))) |
dbg("Diagram %s imagemap: %s" % (diagram, "\n"+str(imgmap))) |
115 |
out.write("\n"+'<a id="%s"></a>' %(diagram) + "\n") |
out.write("\n"+'<a id="%s"></a>' %(diagram) + "\n") |
116 |
out.write(imgmap) |
out.write(imgmap) |
117 |
|
out.write(imgmap_implicit) |
118 |
|
if len(context) > 0: context = '_'+context |
119 |
|
out.write('<img src="'+slashify(relative_path(config.working_directory, config.mp_directory)) \ |
120 |
|
+diagram+context+config.midfix+'.png" usemap="#' \ |
121 |
|
+diagram+'_map" alt="'+diagram+'" id="'+diagram+'_img" />'+"\n") |
122 |
html = html[html.find(">", insert)+1:len(html)] |
html = html[html.find(">", insert)+1:len(html)] |
123 |
out.write(html) |
out.write(html) |
124 |
out.close() |
out.close() |
148 |
config.input_filename = os.path.basename(filepath) |
config.input_filename = os.path.basename(filepath) |
149 |
config.output_filename = os.path.basename(filepath) |
config.output_filename = os.path.basename(filepath) |
150 |
|
|
151 |
|
embed_javascript(filepath) |
152 |
|
|
153 |
htmlfile = open(filepath) |
htmlfile = open(filepath) |
154 |
html = htmlfile.read() |
html = htmlfile.read() |
155 |
htmlfile.close() |
htmlfile.close() |
198 |
if context.endswith(config.midfix+'.html'): |
if context.endswith(config.midfix+'.html'): |
199 |
context = context[0:len(context)-(len(config.midfix)+5)] |
context = context[0:len(context)-(len(config.midfix)+5)] |
200 |
if context.endswith(".html"): context = context[0:len(context)-5] |
if context.endswith(".html"): context = context[0:len(context)-5] |
201 |
context = context+'_implicit' |
create_uml(diagram, context) |
202 |
|
create_uml(diagram, context+'_implicit', scale=0.5) |
|
create_uml(diagram, context, scale=0.5) |
|
203 |
out = open(filepath, "w") |
out = open(filepath, "w") |
204 |
out.write(html[0:insert]); |
out.write(html[0:insert]); |
205 |
out.close() |
out.close() |
206 |
out = open(filepath, "w") |
out = open(filepath, "w") |
207 |
out.write(html[0:insert]); |
out.write(html[0:insert]); |
208 |
dbg("Mapping diagram %s within %s" % (diagram, filepath)) |
dbg("Mapping diagram %s within %s" % (diagram, filepath)) |
209 |
imgmap = get_imagemap(diagram, context, scale=0.5, id_postfix="_implicit") |
imgmap = get_imagemap(diagram, context) |
210 |
dbg("Diagram %s imagemap: %s" % (diagram, "\n"+str(imgmap))) |
imgmap_implicit = get_imagemap(diagram, context+'_implicit', scale=0.5, id_postfix="_implicit") |
211 |
|
dbg("Diagram %s imagemap: %s" % (diagram, "\n"+str(imgmap_implicit))) |
212 |
out.write(imgmap) |
out.write(imgmap) |
213 |
|
out.write(imgmap_implicit) |
214 |
|
if len(context) > 0: context = '_'+context |
215 |
|
out.write('<img src="'+slashify(relative_path(config.working_directory, config.mp_directory)) \ |
216 |
|
+diagram+context+'_implicit'+config.midfix+'.png" usemap="#' \ |
217 |
|
+diagram+'_implicit_map" alt="'+diagram+'" id="'+diagram+'_img" />'+"\n") |
218 |
html = html[insert_left:len(html)] |
html = html[insert_left:len(html)] |
219 |
out.write(html) |
out.write(html) |
220 |
out.close() |
out.close() |
225 |
config.link_base_directory = None |
config.link_base_directory = None |
226 |
|
|
227 |
def is_linked(diagram): |
def is_linked(diagram): |
228 |
log = open(slashify(config.mp_directory)+diagram+config.midfix+'.mp.log').read() |
log_file = open(slashify(config.mp_directory)+diagram+config.midfix+'.mp.log') |
229 |
|
log = log_file.read() |
230 |
|
log_file.close() |
231 |
log = log.replace("\n",'') # MetaPost (mpost) splits lines awkwardly in the log. |
log = log.replace("\n",'') # MetaPost (mpost) splits lines awkwardly in the log. |
232 |
|
|
233 |
# Grep all linked areas from log file. |
# Grep all linked areas from log file. |
240 |
def get_imagemap(diagram, context, scale=1.0, id_postfix=''): |
def get_imagemap(diagram, context, scale=1.0, id_postfix=''): |
241 |
if len(context) > 0: context = '_'+context |
if len(context) > 0: context = '_'+context |
242 |
|
|
243 |
log = open(slashify(config.mp_directory)+diagram+context+config.midfix+'.mp.log').read() |
log_file = open(slashify(config.mp_directory)+diagram+context+config.midfix+'.mp.log') |
244 |
|
log = log_file.read() |
245 |
|
log_file.close() |
246 |
log = log.replace("\n",'') # MetaPost (mpost) splits lines awkwardly in the log. |
log = log.replace("\n",'') # MetaPost (mpost) splits lines awkwardly in the log. |
247 |
|
|
248 |
links = [] |
links = [] |
264 |
link.map_corners(bbox.map_point) |
link.map_corners(bbox.map_point) |
265 |
|
|
266 |
imgmap = "\n"+'<map id="'+diagram+id_postfix+'_map" name="'+diagram+id_postfix+'_map">'+"\n" \ |
imgmap = "\n"+'<map id="'+diagram+id_postfix+'_map" name="'+diagram+id_postfix+'_map">'+"\n" \ |
267 |
+"\n".join([link.imgmapanchor(scale=scale, diagram=diagram) for link in links]) \ |
+"\n".join([link.imgmapanchor(scale=scale, diagram=diagram, context=context) \ |
268 |
+'</map>'+"\n" \ |
for link in links]) \ |
269 |
+'<img src="'+slashify(relative_path(config.working_directory, config.mp_directory)) \ |
+'</map>'+"\n" |
|
+diagram+context+config.midfix+'.png" usemap="#'+diagram+id_postfix+'_map" alt="'+diagram+id_postfix+'" />'+"\n" |
|
|
|
|
270 |
return imgmap |
return imgmap |
271 |
|
|
272 |
def get_targets(diagram): |
def get_targets(diagram): |
276 |
""" |
""" |
277 |
targets = [] |
targets = [] |
278 |
|
|
279 |
log = open(slashify(config.mp_directory)+diagram+config.midfix+'.mp.log').read() |
log_file = open(slashify(config.mp_directory)+diagram+config.midfix+'.mp.log') |
280 |
|
log = log_file.read() |
281 |
|
log_file.close() |
282 |
log = log.replace("\n",'') # MetaPost (mpost) splits lines awkwardly in the log. |
log = log.replace("\n",'') # MetaPost (mpost) splits lines awkwardly in the log. |
283 |
|
|
284 |
# Grep all linked areas from log file. |
# Grep all linked areas from log file. |