0024809: Exception is raised during perform of "bfillds" command on attached shape
[occt.git] / dox / occdoc.tcl
CommitLineData
72b7576f 1# -----------------------------------------------------------------------
2# Script name: CompileDocs.tcl
3# This script compiles OCCT documents from *.md files to HTML pages
4# Author: omy
5# -----------------------------------------------------------------------
6
e5bd0d98 7# get OCCT version from file Standard_Version.hxx (if available)
8proc OverviewDoc_DetectCasVersion {theCasRoot} {
dd21889e 9 set occt_ver 6.7.0
e5bd0d98 10 set occt_ver_add ""
11 if { [file exist $theCasRoot/src/Standard/Standard_Version.hxx] } {
12 set fh [open $theCasRoot/src/Standard/Standard_Version.hxx]
13 set fh_loaded [read $fh]
14 close $fh
15 regexp {[^/]\s*#\s*define\s+OCC_VERSION_COMPLETE\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver
12a45e03 16 regexp {[^/]\s*#\s*define\s+OCC_VERSION_DEVELOPMENT\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver_add
e5bd0d98 17 if { "$occt_ver_add" != "" } { set occt_ver ${occt_ver}.$occt_ver_add }
18 }
19 return $occt_ver
20}
72b7576f 21
e5bd0d98 22# Generates Doxygen configuration file for Overview documentation
e8181411 23proc OverviewDoc_MakeDoxyfile {casDir outDir tagFileDir {doxyFileName} {generatorMode ""} DocFilesList verboseMode searchMode hhcPath mathjaxLocation} {
72b7576f 24
25 set doxyFile [open $doxyFileName "w"]
26 set casroot $casDir
27 set inputDir $casDir/dox
28
29 # Common configs
30 puts $doxyFile "DOXYFILE_ENCODING = UTF-8"
31 puts $doxyFile "PROJECT_NAME = \"Open CASCADE Technology\""
e5bd0d98 32 puts $doxyFile "PROJECT_NUMBER = [OverviewDoc_DetectCasVersion $casDir]"
72b7576f 33 puts $doxyFile "PROJECT_BRIEF = "
e5bd0d98 34 puts $doxyFile "PROJECT_LOGO = $inputDir/resources/occ_logo.png"
72b7576f 35
36 puts $doxyFile "OUTPUT_DIRECTORY = $outDir"
37 puts $doxyFile "CREATE_SUBDIRS = NO"
38 puts $doxyFile "OUTPUT_LANGUAGE = English"
39 puts $doxyFile "ABBREVIATE_BRIEF = \"The \$name class\" \
40 \"The \$name widget\" \
41 \"The \$name file\" \
42 is \
43 provides \
44 specifies \
45 contains \
46 represents \
47 a \
48 an \
49 the"
50
51 puts $doxyFile "FULL_PATH_NAMES = YES"
52 puts $doxyFile "INHERIT_DOCS = YES"
53 puts $doxyFile "TAB_SIZE = 4"
54 puts $doxyFile "MARKDOWN_SUPPORT = YES"
55 puts $doxyFile "EXTRACT_ALL = YES"
56 puts $doxyFile "CASE_SENSE_NAMES = NO"
57 puts $doxyFile "INLINE_INFO = YES"
58 puts $doxyFile "SORT_MEMBER_DOCS = YES"
59 puts $doxyFile "WARNINGS = YES"
60 puts $doxyFile "WARN_IF_UNDOCUMENTED = YES"
61 puts $doxyFile "WARN_IF_DOC_ERROR = YES"
62 puts $doxyFile "WARN_NO_PARAMDOC = NO"
63 puts $doxyFile "WARN_FORMAT = \"\$file:\$line: \$text\""
64 puts $doxyFile "INPUT_ENCODING = UTF-8"
65 puts $doxyFile "FILE_PATTERNS = *.md *.dox "
66 puts $doxyFile "RECURSIVE = YES"
67 puts $doxyFile "SOURCE_BROWSER = NO"
68 puts $doxyFile "INLINE_SOURCES = YES"
69 puts $doxyFile "COLS_IN_ALPHA_INDEX = 5"
70
71 # Generation options
72 puts $doxyFile "GENERATE_DOCSET = NO"
72b7576f 73 puts $doxyFile "GENERATE_CHI = NO"
74 puts $doxyFile "GENERATE_QHP = NO"
75 puts $doxyFile "GENERATE_ECLIPSEHELP = NO"
76 puts $doxyFile "GENERATE_RTF = NO"
77 puts $doxyFile "GENERATE_MAN = NO"
78 puts $doxyFile "GENERATE_XML = NO"
79 puts $doxyFile "GENERATE_DOCBOOK = NO"
80 puts $doxyFile "GENERATE_AUTOGEN_DEF = NO"
81 puts $doxyFile "GENERATE_PERLMOD = NO"
82
f6e968a7 83 # Keep doxygen comments within code blocks
84 puts $doxyFile "STRIP_CODE_COMMENTS = NO"
85
3d68eaf5 86 # Define alias for inserting images to both HRML and PDF at once
87 puts $doxyFile "ALIASES += figure\{1\}=\"\\image html \\1 \\n \\image latex \\1\""
88 puts $doxyFile "ALIASES += figure\{2\}=\"\\image html \\1 \\2 \\n \\image latex \\1 \\2\""
89
e5bd0d98 90 set PARAM_INPUT "INPUT ="
91 set PARAM_IMAGEPATH "IMAGE_PATH = $inputDir/resources/ "
72b7576f 92
93 foreach docFile $DocFilesList {
94 set NEW_IMG_PATH [file normalize [file dirname "$inputDir/$docFile"]]
95 if { [string compare $NEW_IMG_PATH $casroot] != 0 } {
96 if {[file isdirectory "$NEW_IMG_PATH/images"]} {
e5bd0d98 97 append PARAM_IMAGEPATH " $NEW_IMG_PATH/images"
72b7576f 98 }
99 }
100 append PARAM_INPUT " " $inputDir/$docFile
101 }
102 puts $doxyFile $PARAM_INPUT
103 puts $doxyFile $PARAM_IMAGEPATH
72b7576f 104
105 if { $generatorMode == "HTML_ONLY"} {
106 # Set a reference to a TAGFILE
107 if { $tagFileDir != "" } {
108 if {[file exists $tagFileDir/OCCT.tag] == 1} {
109 set tagPath [OverviewDoc_GetRelPath $tagFileDir $outDir/html]
110 puts $doxyFile "TAGFILES = $tagFileDir/OCCT.tag=$tagPath/html"
111 }
112 }
72b7576f 113 # HTML Output
114 puts $doxyFile "GENERATE_LATEX = NO"
8b0857f8 115 puts $doxyFile "GENERATE_HTMLHELP = NO"
72b7576f 116 puts $doxyFile "GENERATE_HTML = YES"
117 puts $doxyFile "HTML_COLORSTYLE_HUE = 220"
118 puts $doxyFile "HTML_COLORSTYLE_SAT = 100"
119 puts $doxyFile "HTML_COLORSTYLE_GAMMA = 80"
120 puts $doxyFile "HTML_TIMESTAMP = YES"
121 puts $doxyFile "HTML_DYNAMIC_SECTIONS = YES"
122 puts $doxyFile "HTML_INDEX_NUM_ENTRIES = 100"
123 puts $doxyFile "DISABLE_INDEX = YES"
124 puts $doxyFile "GENERATE_TREEVIEW = YES"
125 puts $doxyFile "ENUM_VALUES_PER_LINE = 8"
126 puts $doxyFile "TREEVIEW_WIDTH = 250"
127 puts $doxyFile "EXTERNAL_PAGES = NO"
e5bd0d98 128 # HTML Search engine options
129 if { [string tolower $searchMode] == "none" } {
130 puts $doxyFile "SEARCHENGINE = NO"
131 puts $doxyFile "SERVER_BASED_SEARCH = NO"
132 puts $doxyFile "EXTERNAL_SEARCH = NO"
133 } else {
134 puts $doxyFile "SEARCHENGINE = YES"
135 if { [string tolower $searchMode] == "local" } {
136 puts $doxyFile "SERVER_BASED_SEARCH = NO"
137 puts $doxyFile "EXTERNAL_SEARCH = NO"
138 } elseif { [string tolower $searchMode] == "server" } {
139 puts $doxyFile "SERVER_BASED_SEARCH = YES"
140 puts $doxyFile "EXTERNAL_SEARCH = NO"
141 } elseif { [string tolower $searchMode] == "external" } {
142 puts $doxyFile "SERVER_BASED_SEARCH = YES"
143 puts $doxyFile "EXTERNAL_SEARCH = YES"
144 } else {
145 puts "ERROR: Wrong search engine type"
146 close $doxyFile
147 return
148 }
149 }
72b7576f 150 puts $doxyFile "SEARCHDATA_FILE = searchdata.xml"
151 puts $doxyFile "SKIP_FUNCTION_MACROS = YES"
152 # Formula options
153 puts $doxyFile "FORMULA_FONTSIZE = 12"
154 puts $doxyFile "FORMULA_TRANSPARENT = YES"
155 puts $doxyFile "USE_MATHJAX = YES"
156 puts $doxyFile "MATHJAX_FORMAT = HTML-CSS"
e8181411 157 puts $doxyFile "MATHJAX_RELPATH = ${mathjaxLocation}"
72b7576f 158
8b0857f8 159 } elseif { $generatorMode == "CHM_ONLY"} {
160 puts $doxyFile "GENERATE_HTMLHELP = YES"
161 puts $doxyFile "CHM_FILE = ../../overview.chm"
162 puts $doxyFile "HHC_LOCATION = \"$hhcPath\""
163 puts $doxyFile "DISABLE_INDEX = YES"
164 # Formula options
165 puts $doxyFile "FORMULA_FONTSIZE = 12"
166 puts $doxyFile "FORMULA_TRANSPARENT = YES"
167 puts $doxyFile "USE_MATHJAX = YES"
168 puts $doxyFile "MATHJAX_FORMAT = HTML-CSS"
e8181411 169 puts $doxyFile "MATHJAX_RELPATH = ${mathjaxLocation}"
8b0857f8 170
72b7576f 171 } elseif { $generatorMode == "PDF_ONLY"} {
8b0857f8 172 puts $doxyFile "GENERATE_HTMLHELP = NO"
72b7576f 173 puts $doxyFile "GENERATE_HTML = NO"
174 puts $doxyFile "DISABLE_INDEX = YES"
175 puts $doxyFile "GENERATE_TREEVIEW = NO"
176 puts $doxyFile "PREDEFINED = PDF_ONLY"
177 puts $doxyFile "GENERATE_LATEX = YES"
178 puts $doxyFile "COMPACT_LATEX = YES"
179 puts $doxyFile "PDF_HYPERLINKS = YES"
180 puts $doxyFile "USE_PDFLATEX = YES"
181 puts $doxyFile "LATEX_BATCHMODE = YES"
182 puts $doxyFile "LATEX_OUTPUT = latex"
183 puts $doxyFile "LATEX_CMD_NAME = latex"
184 puts $doxyFile "MAKEINDEX_CMD_NAME = makeindex"
185 }
186
187 close $doxyFile
188}
189
190# Returns the relative path between two directories
191proc OverviewDoc_GetRelPath {targetFile currentpath} {
192 set cc [file split [file normalize $currentpath]]
193 set tt [file split [file normalize $targetFile]]
194
195 if {![string equal [lindex $cc 0] [lindex $tt 0]]} {
196 # not on *n*x then
197 return -code error "$targetFile not on same volume as $currentpath"
198 }
199 while {[string equal [lindex $cc 0] [lindex $tt 0]] && [llength $cc] > 0} {
200 # discard matching components from the front
201 set cc [lreplace $cc 0 0]
202 set tt [lreplace $tt 0 0]
203 }
204 set prefix ""
205 if {[llength $cc] == 0} {
206 # just the file name, so targetFile is lower down (or in same place)
207 set prefix "."
208 }
209 # step up the tree
210 for {set i 0} {$i < [llength $cc]} {incr i} {
211 append prefix " .."
212 }
213 # stick it all together (the eval is to flatten the targetFile list)
214 return [eval file join $prefix $tt]
215}
216
217# Prints Help message
218proc OverviewDoc_PrintHelpMessage {} {
e5bd0d98 219 puts "\nUsage : occdoc \[-h\] \[-html\] \[-pdf\] \[-m=<list of files>\] \[-l=<document name>\] \[-v\] \[-s\]"
72b7576f 220 puts ""
221 puts " Options are : "
e8181411 222 puts " -html : To generate HTML files"
223 puts " (cannot be used with -pdf or -chm)"
224 puts " -pdf : To generate PDF files"
225 puts " (cannot be used with -html or chm)"
226 puts " -chm : To generate CHM files"
227 puts " (cannot be used with -html or pdf)"
228 puts " -hhc : To define path to hhc - chm generator"
229 puts " : is used with just -chm option"
230 puts " -m=<modules_list> : Specifies list of documents to generate."
231 puts " If it is not specified, all files "
232 puts " mentioned in FILES.txt are processed."
233 puts " -l=<document_name> : Specifies the document caption "
234 puts " for a single document"
235 puts " -h : Prints help message"
236 puts " -v : Specifies the Verbose mode"
237 puts " (info on all script actions is shown)"
238 puts " -s=<search_mode> : Specifies the Search mode of HTML documents."
239 puts " Can be: none | local | server | external"
240 puts " : Can be used only with -html option"
241 puts " -mathjax=<path> : To use local or alternative copy of MathJax"
72b7576f 242}
243
244# Parses command line arguments
245proc OverviewDoc_ParseArguments {arguments} {
246 global args_names
247 global args_values
248 set args_names {}
249 array set args_values {}
250
251 foreach arg $arguments {
252 if {[regexp {^(-)[a-z]+$} $arg] == 1} {
253 set name [string range $arg 1 [string length $arg]-1]
254 lappend args_names $name
255 set args_values($name) "NULL"
256 continue
257 } elseif {[regexp {^(-)[a-z]+=.+$} $arg] == 1} {
258 set equal_symbol_position [string first "=" $arg]
259 set name [string range $arg 1 $equal_symbol_position-1]
260 lappend args_names $name
261 set value [string range $arg $equal_symbol_position+1 [string length $arguments]-1]
262
263 # To parse a list of values for -m parameter
264 if { [string first "," $value] != -1 } {
265 set value [split $value ","];
266 }
267 set args_values($name) $value
268 } else {
269 puts "Error in argument $arg"
270 return 1
271 }
272 }
273 return 0
274}
275
276# Loads a list of docfiles from file FILES.txt
277proc OverviewDoc_LoadFilesList {} {
278
279 set INPUTDIR [file normalize [file dirname [info script]]]
280
281 global available_docfiles
282 set available_docfiles {}
283
284 # Read data from file
285 if { [file exists "$INPUTDIR/FILES.txt"] == 1 } {
286 set FILE [open "$INPUTDIR/FILES.txt" r]
287 while {1} {
e5bd0d98 288 set line [string trim [gets $FILE]]
289
290 # trim possible comments starting with '#'
291 set line [regsub {\#.*} $line {}]
292
72b7576f 293 if {$line != ""} {
294 lappend available_docfiles $line
295 }
296
297 if {[eof $FILE]} {
298 close $FILE
299 break
300 }
301 }
302 } else {
303 return -1
304 }
305 return 0
306}
307
308# Writes new tex file for conversion from tex to pdf for a specific doc
309proc OverviewDoc_MakeRefmanTex {fileName latexDir docLabel verboseMode} {
310
311 if {$verboseMode == "YES"} {
312 puts "INFO: Making refman.tex file for $fileName"
313 }
314 set DOCNAME "$latexDir/refman.tex"
315 if {[file exists $DOCNAME] == 1} {
316 file delete -force $DOCNAME
317 }
3d68eaf5 318
319 set year [clock format [clock seconds] -format {%Y}]
320
72b7576f 321 set texfile [open $DOCNAME w]
322
323 puts $texfile "\\batchmode"
324 puts $texfile "\\nonstopmode"
325 puts $texfile "\\documentclass\[oneside\]{article}"
326 puts $texfile "\n% Packages required by doxygen"
327 puts $texfile "\\usepackage{calc}"
328 puts $texfile "\\usepackage{doxygen}"
329 puts $texfile "\\usepackage{graphicx}"
330 puts $texfile "\\usepackage\[utf8\]{inputenc}"
331 puts $texfile "\\usepackage{makeidx}"
332 puts $texfile "\\usepackage{multicol}"
333 puts $texfile "\\usepackage{multirow}"
334 puts $texfile "\\usepackage{textcomp}"
335 puts $texfile "\\usepackage{amsmath}"
336 puts $texfile "\\usepackage\[table\]{xcolor}"
337 puts $texfile "\\usepackage{indentfirst}"
338 puts $texfile ""
339 puts $texfile "% Font selection"
340 puts $texfile "\\usepackage\[T1\]{fontenc}"
341 puts $texfile "\\usepackage{mathptmx}"
342 puts $texfile "\\usepackage\[scaled=.90\]{helvet}"
343 puts $texfile "\\usepackage{courier}"
344 puts $texfile "\\usepackage{amssymb}"
345 puts $texfile "\\usepackage{sectsty}"
346 puts $texfile "\\renewcommand{\\familydefault}{\\sfdefault}"
347 puts $texfile "\\allsectionsfont{%"
348 puts $texfile " \\fontseries{bc}\\selectfont%"
349 puts $texfile " \\color{darkgray}%"
350 puts $texfile "}"
351 puts $texfile "\\renewcommand{\\DoxyLabelFont}{%"
352 puts $texfile " \\fontseries{bc}\\selectfont%"
353 puts $texfile " \\color{darkgray}%"
354 puts $texfile "}"
355 puts $texfile ""
356 puts $texfile "% Page & text layout"
357 puts $texfile "\\usepackage{geometry}"
358 puts $texfile "\\geometry{%"
359 puts $texfile " a4paper,%"
360 puts $texfile " top=2.5cm,%"
361 puts $texfile " bottom=2.5cm,%"
362 puts $texfile " left=2.5cm,%"
363 puts $texfile " right=2.5cm%"
364 puts $texfile "}"
365 puts $texfile "\\tolerance=750"
366 puts $texfile "\\hfuzz=15pt"
367 puts $texfile "\\hbadness=750"
368 puts $texfile "\\setlength{\\emergencystretch}{15pt}"
e5bd0d98 369 puts $texfile "\\setlength{\\parindent}{0cm}";#0.75cm
370 puts $texfile "\\setlength{\\parskip}{0.2cm}"; #0.2
72b7576f 371 puts $texfile "\\makeatletter"
372 puts $texfile "\\renewcommand{\\paragraph}{%"
373 puts $texfile " \@startsection{paragraph}{4}{0ex}{-1.0ex}{1.0ex}{%"
374 puts $texfile "\\normalfont\\normalsize\\bfseries\\SS@parafont%"
375 puts $texfile " }%"
376 puts $texfile "}"
377 puts $texfile "\\renewcommand{\\subparagraph}{%"
378 puts $texfile " \\@startsection{subparagraph}{5}{0ex}{-1.0ex}{1.0ex}{%"
379 puts $texfile "\\normalfont\\normalsize\\bfseries\\SS@subparafont%"
380 puts $texfile " }%"
381 puts $texfile "}"
382 puts $texfile "\\makeatother"
383 puts $texfile ""
384 puts $texfile "% Headers & footers"
385 puts $texfile "\\usepackage{fancyhdr}"
386 puts $texfile "\\pagestyle{fancyplain}"
387 puts $texfile "\\fancyhead\[LE\]{\\fancyplain{}{\\bfseries\\thepage}}"
388 puts $texfile "\\fancyhead\[CE\]{\\fancyplain{}{}}"
389 puts $texfile "\\fancyhead\[RE\]{\\fancyplain{}{\\bfseries\\leftmark}}"
390 puts $texfile "\\fancyhead\[LO\]{\\fancyplain{}{\\bfseries\\rightmark}}"
391 puts $texfile "\\fancyhead\[CO\]{\\fancyplain{}{}}"
392 puts $texfile "\\fancyhead\[RO\]{\\fancyplain{}{\\bfseries\\thepage}}"
393 puts $texfile "\\fancyfoot\[LE\]{\\fancyplain{}{}}"
394 puts $texfile "\\fancyfoot\[CE\]{\\fancyplain{}{}}"
3d68eaf5 395 puts $texfile "\\fancyfoot\[RE\]{\\fancyplain{}{\\bfseries\\scriptsize Copyright (c) Open CASCADE $year}}"
396 puts $texfile "\\fancyfoot\[LO\]{\\fancyplain{}{\\bfseries\\scriptsize Copyright (c) Open CASCADE $year}}"
72b7576f 397 puts $texfile "\\fancyfoot\[CO\]{\\fancyplain{}{}}"
398 puts $texfile "\\fancyfoot\[RO\]{\\fancyplain{}{}}"
399 puts $texfile "\\renewcommand{\\footrulewidth}{0.4pt}"
400 puts $texfile "\\renewcommand{\\sectionmark}\[1\]{%"
401 puts $texfile " \\markright{\\thesection\\ #1}%"
402 puts $texfile "}"
403 puts $texfile ""
404 puts $texfile "% Indices & bibliography"
405 puts $texfile "\\usepackage{natbib}"
406 puts $texfile "\\usepackage\[titles\]{tocloft}"
407 puts $texfile "\\renewcommand{\\cftsecleader}{\\cftdotfill{\\cftdotsep}}"
408 puts $texfile "\\setcounter{tocdepth}{3}"
409 puts $texfile "\\setcounter{secnumdepth}{5}"
410 puts $texfile "\\makeindex"
411 puts $texfile ""
412 puts $texfile "% Hyperlinks (required, but should be loaded last)"
413 puts $texfile "\\usepackage{ifpdf}"
414 puts $texfile "\\ifpdf"
415 puts $texfile " \\usepackage\[pdftex,pagebackref=true\]{hyperref}"
416 puts $texfile "\\else"
417 puts $texfile " \\usepackage\[ps2pdf,pagebackref=true\]{hyperref}"
418 puts $texfile "\\fi"
419 puts $texfile "\\hypersetup{%"
420 puts $texfile " colorlinks=true,%"
421 puts $texfile " linkcolor=black,%"
422 puts $texfile " citecolor=black,%"
423 puts $texfile " urlcolor=blue,%"
424 puts $texfile " unicode%"
425 puts $texfile "}"
426 puts $texfile ""
427 puts $texfile "% Custom commands"
428 puts $texfile "\\newcommand{\\clearemptydoublepage}{%"
429 puts $texfile " \\newpage{\\pagestyle{empty}\\cleardoublepage}%"
430 puts $texfile "}"
431 puts $texfile "\n"
432 puts $texfile "%===== C O N T E N T S =====\n"
433 puts $texfile "\\begin{document}"
434 puts $texfile ""
435 puts $texfile "% Titlepage & ToC"
436 puts $texfile "\\hypersetup{pageanchor=false}"
437 puts $texfile "\\pagenumbering{roman}"
438 puts $texfile "\\begin{titlepage}"
439 puts $texfile "\\vspace*{7cm}"
440 puts $texfile "\\begin{center}%"
e5bd0d98 441 puts $texfile "\\includegraphics\[width=0.75\\textwidth, height=0.2\\textheight\]{../../../dox/resources/occt_logo.png}\\\\"; #\\\\\\\\
442 puts $texfile "{\\Large Open C\\-A\\-S\\-C\\-A\\-D\\-E Technology \\\\\[1ex\]\\Large [OverviewDoc_DetectCasVersion $latexDir/../../../] }\\\\"
72b7576f 443 puts $texfile "\\vspace*{1cm}"
444 puts $texfile "{\\Large $docLabel}\\\\"
445 puts $texfile "\\vspace*{1cm}"
47d9074a 446# puts $texfile "{\\large Generated by Doxygen 1.8.4}\\\\"
72b7576f 447 puts $texfile "\\vspace*{0.5cm}"
448 puts $texfile "{\\small \\today}\\"
449 puts $texfile "\\end{center}"
450 puts $texfile "\\end{titlepage}"
451 puts $texfile "\\clearpage"
452 puts $texfile "\\pagenumbering{roman}"
453 puts $texfile "\\tableofcontents"
454 puts $texfile "\\newpage"
455 puts $texfile "\\pagenumbering{arabic}"
456 puts $texfile "\\hypersetup{pageanchor=true}"
457 puts $texfile ""
e5bd0d98 458 puts $texfile "\\let\\stdsection\\section"
459 puts $texfile " \\renewcommand\\section{\\pagebreak\\stdsection}"
72b7576f 460 puts $texfile "\\hypertarget{$fileName}{}"
461 puts $texfile "\\input{$fileName}"
462 puts $texfile ""
463 puts $texfile "% Index"
464 puts $texfile "\\newpage"
465 puts $texfile "\\phantomsection"
466 puts $texfile "\\addcontentsline{toc}{part}{Index}"
467 puts $texfile "\\printindex\n"
468 puts $texfile "\\end{document}"
469
470 close $texfile
471}
472
473# Postprocesses generated TeX files
474proc OverviewDoc_ProcessTex {{texFiles {}} {latexDir} verboseMode} {
475
476 foreach TEX $texFiles {
477 if {$verboseMode == "YES"} {
478 puts "INFO: Preprocessing file $TEX"
479 }
dba69de2 480
481 if {![file exists $TEX]} {
482 puts "file $TEX doesn't exist"
483 return
484 }
485
72b7576f 486 set IN_F [open "$TEX" r]
487 set TMPFILENAME "$latexDir/temp.tex"
dba69de2 488
72b7576f 489 set OUT_F [open $TMPFILENAME w]
490
491 while {1} {
492 set line [gets $IN_F]
493 if { [string first "\\includegraphics" $line] != -1 } {
3d68eaf5 494 # replace svg extension by pdf
495 set line [regsub {[.]svg} $line ".pdf"]
72b7576f 496 # Center images in TeX files
497 set line "\\begin{center}\n $line\n\\end{center}"
498 } elseif { [string first "\\subsection" $line] != -1 } {
499 # Replace \subsection with \section tag
500 regsub -all "\\\\subsection" $line "\\\\section" line
501 } elseif { [string first "\\subsubsection" $line] != -1 } {
502 # Replace \subsubsection with \subsection tag
503 regsub -all "\\\\subsubsection" $line "\\\\subsection" line
504 } elseif { [string first "\\paragraph" $line] != -1 } {
505 # Replace \paragraph with \subsubsection tag
506 regsub -all "\\\\paragraph" $line "\\\\subsubsection" line
507 }
508 puts $OUT_F $line
509
510 if {[eof $IN_F]} {
511 close $IN_F
512 close $OUT_F
513 break
514 }
515 }
516 file delete -force $TEX
517 file rename $TMPFILENAME $TEX
518 }
519}
520
3d68eaf5 521# Convert SVG files to PDF format to allow including them to PDF
522# (requires InkScape to be in PATH)
523proc OverviewDoc_ProcessSvg {latexDir verboseMode} {
524
525 foreach file [glob -nocomplain $latexDir/*.svg] {
526 if {$verboseMode == "YES"} {
527 puts "INFO: Converting file $file"
528 }
529
530 set pdffile "[file rootname $file].pdf"
531 if { [catch {exec inkscape -z -D --file=$file --export-pdf=$pdffile} res] } {
532 puts "Error: $res"
533 puts "Conversion failed; check that Inkscape is in PATH!"
534 puts "SVG images will be lost in PDF documents"
535 return
536 }
537 }
538}
539
72b7576f 540# Main procedure for documents compilation
e8181411 541proc OverviewDoc_Main { {docfiles {}} generatorMode docLabel verboseMode searchMode hhcPath mathjaxLocation} {
72b7576f 542
543 set INDIR [file normalize [file dirname [info script]]]
544 set CASROOT [file normalize [file dirname "$INDIR/../../"]]
545 set OUTDIR $CASROOT/doc
546 set PDFDIR $OUTDIR/overview/pdf
547 set HTMLDIR $OUTDIR/overview/html
548 set LATEXDIR $OUTDIR/overview/latex
549 set TAGFILEDIR $OUTDIR/refman
550 set DOXYFILE $OUTDIR/OCCT.cfg
551
552 # Create or clean the output folders
553 if {[file exists $OUTDIR] == 0} {
554 file mkdir $OUTDIR
555 }
556 if {[file exists $HTMLDIR] == 0} {
557 file mkdir $HTMLDIR
558 }
72b7576f 559 if {[file exists $PDFDIR] == 0} {
560 file mkdir $PDFDIR
561 }
e5bd0d98 562
563 if {[file exists $LATEXDIR]} {
564 #file delete {*}[glob -nocomplain $LATEXDIR/*.*]
565 file delete -force $LATEXDIR
566 }
567 file mkdir $LATEXDIR
e8181411 568
569 # is MathJax HLink?
570 set mathjax_relative_location $mathjaxLocation
571 if { [file isdirectory "$mathjaxLocation"] == 1 } {
572 if { $generatorMode == "HTML_ONLY"} {
573 # related path
574 set mathjax_relative_location [relativePath $HTMLDIR $mathjaxLocation]
575 } elseif { $generatorMode == "CHM_ONLY"} {
576 # absolute path
577 set mathjax_relative_location [file normalize $mathjaxLocation]
578 }
579 }
72b7576f 580
581 # Run tools to compile documents
e5bd0d98 582 puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generating Doxyfile..."
583
e8181411 584 OverviewDoc_MakeDoxyfile $CASROOT "$OUTDIR/overview" $TAGFILEDIR $DOXYFILE $generatorMode $docfiles $verboseMode $searchMode $hhcPath $mathjax_relative_location
72b7576f 585
586 # Run doxygen tool
3d68eaf5 587 set starttimestamp [clock format [clock seconds] -format {%Y-%m-%d %H:%M}]
72b7576f 588 if { $generatorMode == "HTML_ONLY"} {
3d68eaf5 589 puts "$starttimestamp Generating HTML files..."
8b0857f8 590 } elseif { $generatorMode == "CHM_ONLY" } {
3d68eaf5 591 puts "$starttimestamp Generating CHM file..."
72b7576f 592 }
593 set RESULT [catch {exec doxygen $DOXYFILE > $OUTDIR/doxygen_out.log} DOX_ERROR]
594 if {$RESULT != 0} {
595 if {[llength [split $DOX_ERROR "\n"]] > 1} {
596 if {$verboseMode == "YES"} {
3d68eaf5 597 puts "Error running Doxygen; see log in\n$OUTDIR/doxygen_warnings_and_errors.log"
72b7576f 598 }
599 set DOX_ERROR_FILE [open "$OUTDIR/doxygen_warnings_and_errors.log" "w"]
600 puts $DOX_ERROR_FILE $DOX_ERROR
601 close $DOX_ERROR_FILE
602 } else {
603 puts $DOX_ERROR
604 }
605 }
606 # Close the Doxygen application
607 after 300
608
609 # Start PDF generation routine
610 if { $generatorMode == "PDF_ONLY" } {
e5bd0d98 611 puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generating PDF files..."
72b7576f 612
613 set OS $::tcl_platform(platform)
614 if { $OS == "unix" } {
615 set PREFIX ".sh"
616 } elseif { $OS == "windows" } {
617 set PREFIX ".bat"
618 }
619
620 # Prepare a list of TeX files, generated by Doxygen
621 cd $LATEXDIR
622
623 set TEXFILES [glob $LATEXDIR -type f -directory $LATEXDIR -tails "*.tex" ]
624 set REFMAN_IDX [lsearch $TEXFILES "refman.tex"]
625 set TEXFILES [lreplace $TEXFILES $REFMAN_IDX $REFMAN_IDX]
dba69de2 626
72b7576f 627
628 set IDX [lsearch $TEXFILES "$LATEXDIR"]
629 while { $IDX != -1} {
630 set TEXFILES [lreplace $TEXFILES $IDX $IDX]
631 set IDX [lsearch $TEXFILES "$LATEXDIR"]
632 }
633
e5bd0d98 634 if {$verboseMode == "YES"} {
635 puts "Preprocessing generated TeX files..."
636 }
72b7576f 637 OverviewDoc_ProcessTex $TEXFILES $LATEXDIR $verboseMode
e5bd0d98 638
3d68eaf5 639 if {$verboseMode == "YES"} {
640 puts "Converting SVG images to PNG format..."
641 }
642 OverviewDoc_ProcessSvg $LATEXDIR $verboseMode
643
e5bd0d98 644 if {$verboseMode == "YES"} {
645 puts "Generating PDF files from TeX files..."
646 }
72b7576f 647 foreach TEX $TEXFILES {
648 # Rewrite existing REFMAN.tex file...
649 set TEX [string range $TEX 0 [ expr "[string length $TEX] - 5"]]
650 OverviewDoc_MakeRefmanTex $TEX $LATEXDIR $docLabel $verboseMode
651
652 if {$verboseMode == "YES"} {
653 puts "INFO: Generating PDF file from $TEX"
e5bd0d98 654 # ...and use it to generate PDF from TeX...
655 puts "Executing $LATEXDIR/make$PREFIX..."
72b7576f 656 }
72b7576f 657 set RESULT [catch {eval exec [auto_execok $LATEXDIR/make$PREFIX] > "$OUTDIR/pdflatex_out.log"} LaTeX_ERROR]
658 if {$RESULT != 0} {
659 if {[llength [split $LaTeX_ERROR "\n"]] > 1} {
e5bd0d98 660 if {$verboseMode == "YES"} {
3d68eaf5 661 puts "Errors running Latex; see log in \n$OUTDIR/pdflatex_warnings_and_errors.log"
e5bd0d98 662 }
72b7576f 663 set LaTeX_ERROR_FILE [open "$OUTDIR/pdflatex_warnings_and_errors.log" "w"]
664 puts $LaTeX_ERROR_FILE $LaTeX_ERROR
665 close $LaTeX_ERROR_FILE
666 } else {
667 puts $DOX_ERROR
668 }
669 }
670
671 # ...and place it to the specific folder
672 if { [file exists $PDFDIR/$TEX.pdf] == 1 } {
673 file delete -force $PDFDIR/$TEX.pdf
674 }
dba69de2 675
676 if {![file exists "$LATEXDIR/refman.pdf"]} {
3d68eaf5 677 puts "Error: Latex failed to create $LATEXDIR/refman.pdf"
dba69de2 678 return
679 }
680
72b7576f 681 file rename $LATEXDIR/refman.pdf "$PDFDIR/$TEX.pdf"
682 }
72b7576f 683 }
684
685 cd $INDIR
e5bd0d98 686 puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generation completed"
72b7576f 687 if { $generatorMode == "HTML_ONLY" } {
3d68eaf5 688 puts "View generated HTML documentation by opening:"
689 puts "$OUTDIR/overview/html/index.html"
72b7576f 690 }
691 if { $generatorMode == "PDF_ONLY" } {
3d68eaf5 692 puts "PDF files are generated in folder:"
693 puts "$OUTDIR/overview/pdf"
72b7576f 694 }
72b7576f 695}
696
e8181411 697proc relativePath {thePathFrom thePathTo} {
698 if { [file isdirectory "$thePathFrom"] == 0 } {
699 return ""
700 }
701
702 set aPathFrom [file normalize "$thePathFrom"]
703 set aPathTo [file normalize "$thePathTo"]
704
705 set aCutedPathFrom "${aPathFrom}/dummy"
706 set aRelatedDeepPath ""
707
708 while { "$aCutedPathFrom" != [file normalize "$aCutedPathFrom/.."] } {
709 set aCutedPathFrom [file normalize "$aCutedPathFrom/.."]
710 # does aPathTo contain aCutedPathFrom?
711 regsub -all $aCutedPathFrom $aPathTo "" aPathFromAfterCut
712 if { "$aPathFromAfterCut" != "$aPathTo" } { # if so
713 if { "$aCutedPathFrom" == "$aPathFrom" } { # just go higher, for example, ./somefolder/someotherfolder
714 set aPathTo ".${aPathTo}"
715 } elseif { "$aCutedPathFrom" == "$aPathTo" } { # remove the last "/"
716 set aRelatedDeepPath [string replace $aRelatedDeepPath end end ""]
717 }
718 regsub -all $aCutedPathFrom $aPathTo $aRelatedDeepPath aPathToAfterCut
719 regsub -all "//" $aPathToAfterCut "/" aPathToAfterCut
720 return $aPathToAfterCut
721 }
722 set aRelatedDeepPath "$aRelatedDeepPath../"
723
724 }
725
726 return $thePathTo
727}
728
72b7576f 729# A command for User Documentation compilation
730proc occdoc {args} {
731 # Programm options
e5bd0d98 732 set GEN_MODE "HTML_ONLY"
733
72b7576f 734 set DOCFILES {}
e5bd0d98 735 set DOCLABEL "Default OCCT Document"
736 set VERB_MODE "NO"
737 set SEARCH_MODE "none"
8b0857f8 738 set hhcPath ""
e5bd0d98 739
e8181411 740 set mathjax_location "http://cdn.mathjax.org/mathjax/latest"
741 set mathjax_js_name "MathJax.js"
742
72b7576f 743 global available_docfiles
8b0857f8 744 global tcl_platform
72b7576f 745 global args_names
746 global args_values
8b0857f8 747 global env
72b7576f 748
749 # Load list of docfiles
750 if { [OverviewDoc_LoadFilesList] != 0 } {
751 puts "ERROR: File FILES.txt was not found"
752 return
753 }
754
755 # Parse CL arguments
756 if {[OverviewDoc_ParseArguments $args] == 1} {
757 return
758 }
8b0857f8 759
760 foreach arg_n $args_names {
e5bd0d98 761 if {$arg_n == "h"} {
762 OverviewDoc_PrintHelpMessage
763 return
764 } elseif {$arg_n == "html"} {
72b7576f 765 set GEN_MODE "HTML_ONLY"
8b0857f8 766 } elseif {$arg_n == "chm"} {
767 set GEN_MODE "CHM_ONLY"
768
769 if {"$tcl_platform(platform)" == "windows" && [lsearch $args_names hhc] == -1} {
770 if { [info exist env(ProgramFiles\(x86\))] } {
771 set hhcPath "$env(ProgramFiles\(x86\))\\HTML Help Workshop\\hhc.exe"
772 puts "Info: hhc found: $hhcPath"
773 } elseif { [info exist env(ProgramFiles)] } {
774 set hhcPath "$env(ProgramFiles)\\HTML Help Workshop\\hhc.exe"
775 puts "Info: hhc found: $hhcPath"
776 }
777
778 if { ! [file exists $hhcPath] } {
779 puts "Error: HTML Help Compiler is not found in standard location [file dirname $hhcPath]; use option -hhc"
780 return
781 }
782 }
783
784 } elseif {$arg_n == "hhc"} {
785 global tcl_platform
786 if { $tcl_platform(platform) != "windows" } {
787 continue
788 }
789
790 if {$args_values(hhc) != "NULL"} {
791 set hhcPath $args_values(hhc)
792 if { [file isdirectory $hhcPath] } {
793 set hhcPath [file join ${hhcPath} hhc.exe]
794 }
795 if { ! [file exists $hhcPath] } {
796 puts "Error: HTML Help Compiler is not found in $hhcPath"
797 return
798 }
799 } else {
800 puts "Error in argument hhc"
801 return
802 }
803
e5bd0d98 804 } elseif {$arg_n == "pdf"} {
72b7576f 805 set GEN_MODE "PDF_ONLY"
e5bd0d98 806 } elseif {$arg_n == "v"} {
807 set VERB_MODE "YES"
808 } elseif {$arg_n == "m"} {
809 if {$args_values(m) != "NULL"} {
810 set DOCFILES $args_values(m)
811 } else {
812 puts "Error in argument m"
813 return
814 }
8b0857f8 815
e5bd0d98 816 # Check if all chosen docfiles are correct
817 foreach docfile $DOCFILES {
818 if { [lsearch $available_docfiles $docfile] == -1 } {
819 puts "File \"$docfile\" is not presented in the list of available docfiles"
820 puts "Please, specify the correct docfile name"
821 return
822 } else {
823 puts "File $docfile is presented in FILES.TXT"
824 }
825 }
826 } elseif {$arg_n == "l"} {
827 if { [llength $DOCFILES] <= 1 } {
828 if {$args_values(l) != "NULL"} {
829 set DOCLABEL $args_values(l)
830 } else {
831 puts "Error in argument l"
832 return
72b7576f 833 }
e5bd0d98 834 }
835 } elseif {$arg_n == "s"} {
836 if {$args_values(s) != "NULL"} {
837 set SEARCH_MODE $args_values(s)
838 } else {
839 puts "Error in argument s"
72b7576f 840 return
e5bd0d98 841 }
e8181411 842 } elseif {$arg_n == "mathjax"} {
843 if {![info exists args_values(pdf)]} {
844 set possible_mathjax_loc $args_values(mathjax)
845 if {[file exist [file join $possible_mathjax_loc $mathjax_js_name]]} {
846 set mathjax_location $args_values(mathjax)
847 puts "$mathjax_location"
848 } else {
849 puts "Warning: $mathjax_js_name isn't found in $possible_mathjax_loc."
850 puts " MathJax will be used from $mathjax_location"
851 }
852 } else {
853 puts "Info: MathJax is not used with pdf and will be ignored"
854 }
e5bd0d98 855 } else {
856 puts "\nWrong argument: $arg_n"
857 OverviewDoc_PrintHelpMessage
858 return
72b7576f 859 }
e5bd0d98 860 }
861
862 # Specify verbose mode
863 if { $GEN_MODE != "PDF_ONLY" && [llength $DOCFILES] > 1 } {
864 set DOCLABEL ""
865 }
72b7576f 866
e5bd0d98 867 # If we don't specify list for docfiles with -m argument,
868 # we assume that we have to generate all docfiles
869 if { [llength $DOCFILES] == 0 } {
870 set DOCFILES $available_docfiles
871 }
72b7576f 872
e5bd0d98 873 # Start main activities
e8181411 874 OverviewDoc_Main $DOCFILES $GEN_MODE $DOCLABEL $VERB_MODE $SEARCH_MODE $hhcPath $mathjax_location
72b7576f 875}