0024346: Documentation - provide Coding Rules document
[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} {
9 set occt_ver 16.7.0
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
16 regexp {#\s*define\s+OCC_VERSION_DEVELOPMENT\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver_add
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
8b0857f8 23proc OverviewDoc_MakeDoxyfile {casDir outDir tagFileDir {doxyFileName} {generatorMode ""} DocFilesList verboseMode searchMode hhcPath} {
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
e5bd0d98 86 set PARAM_INPUT "INPUT ="
87 set PARAM_IMAGEPATH "IMAGE_PATH = $inputDir/resources/ "
72b7576f 88
89 foreach docFile $DocFilesList {
90 set NEW_IMG_PATH [file normalize [file dirname "$inputDir/$docFile"]]
91 if { [string compare $NEW_IMG_PATH $casroot] != 0 } {
92 if {[file isdirectory "$NEW_IMG_PATH/images"]} {
e5bd0d98 93 append PARAM_IMAGEPATH " $NEW_IMG_PATH/images"
72b7576f 94 }
95 }
96 append PARAM_INPUT " " $inputDir/$docFile
97 }
98 puts $doxyFile $PARAM_INPUT
99 puts $doxyFile $PARAM_IMAGEPATH
72b7576f 100
101 if { $generatorMode == "HTML_ONLY"} {
102 # Set a reference to a TAGFILE
103 if { $tagFileDir != "" } {
104 if {[file exists $tagFileDir/OCCT.tag] == 1} {
105 set tagPath [OverviewDoc_GetRelPath $tagFileDir $outDir/html]
106 puts $doxyFile "TAGFILES = $tagFileDir/OCCT.tag=$tagPath/html"
107 }
108 }
72b7576f 109 # HTML Output
110 puts $doxyFile "GENERATE_LATEX = NO"
8b0857f8 111 puts $doxyFile "GENERATE_HTMLHELP = NO"
72b7576f 112 puts $doxyFile "GENERATE_HTML = YES"
113 puts $doxyFile "HTML_COLORSTYLE_HUE = 220"
114 puts $doxyFile "HTML_COLORSTYLE_SAT = 100"
115 puts $doxyFile "HTML_COLORSTYLE_GAMMA = 80"
116 puts $doxyFile "HTML_TIMESTAMP = YES"
117 puts $doxyFile "HTML_DYNAMIC_SECTIONS = YES"
118 puts $doxyFile "HTML_INDEX_NUM_ENTRIES = 100"
119 puts $doxyFile "DISABLE_INDEX = YES"
120 puts $doxyFile "GENERATE_TREEVIEW = YES"
121 puts $doxyFile "ENUM_VALUES_PER_LINE = 8"
122 puts $doxyFile "TREEVIEW_WIDTH = 250"
123 puts $doxyFile "EXTERNAL_PAGES = NO"
e5bd0d98 124 # HTML Search engine options
125 if { [string tolower $searchMode] == "none" } {
126 puts $doxyFile "SEARCHENGINE = NO"
127 puts $doxyFile "SERVER_BASED_SEARCH = NO"
128 puts $doxyFile "EXTERNAL_SEARCH = NO"
129 } else {
130 puts $doxyFile "SEARCHENGINE = YES"
131 if { [string tolower $searchMode] == "local" } {
132 puts $doxyFile "SERVER_BASED_SEARCH = NO"
133 puts $doxyFile "EXTERNAL_SEARCH = NO"
134 } elseif { [string tolower $searchMode] == "server" } {
135 puts $doxyFile "SERVER_BASED_SEARCH = YES"
136 puts $doxyFile "EXTERNAL_SEARCH = NO"
137 } elseif { [string tolower $searchMode] == "external" } {
138 puts $doxyFile "SERVER_BASED_SEARCH = YES"
139 puts $doxyFile "EXTERNAL_SEARCH = YES"
140 } else {
141 puts "ERROR: Wrong search engine type"
142 close $doxyFile
143 return
144 }
145 }
72b7576f 146 puts $doxyFile "SEARCHDATA_FILE = searchdata.xml"
147 puts $doxyFile "SKIP_FUNCTION_MACROS = YES"
148 # Formula options
149 puts $doxyFile "FORMULA_FONTSIZE = 12"
150 puts $doxyFile "FORMULA_TRANSPARENT = YES"
151 puts $doxyFile "USE_MATHJAX = YES"
152 puts $doxyFile "MATHJAX_FORMAT = HTML-CSS"
153 puts $doxyFile "MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest"
154
8b0857f8 155 } elseif { $generatorMode == "CHM_ONLY"} {
156 puts $doxyFile "GENERATE_HTMLHELP = YES"
157 puts $doxyFile "CHM_FILE = ../../overview.chm"
158 puts $doxyFile "HHC_LOCATION = \"$hhcPath\""
159 puts $doxyFile "DISABLE_INDEX = YES"
160 # Formula options
161 puts $doxyFile "FORMULA_FONTSIZE = 12"
162 puts $doxyFile "FORMULA_TRANSPARENT = YES"
163 puts $doxyFile "USE_MATHJAX = YES"
164 puts $doxyFile "MATHJAX_FORMAT = HTML-CSS"
165 puts $doxyFile "MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest"
166
72b7576f 167 } elseif { $generatorMode == "PDF_ONLY"} {
8b0857f8 168 puts $doxyFile "GENERATE_HTMLHELP = NO"
72b7576f 169 puts $doxyFile "GENERATE_HTML = NO"
170 puts $doxyFile "DISABLE_INDEX = YES"
171 puts $doxyFile "GENERATE_TREEVIEW = NO"
172 puts $doxyFile "PREDEFINED = PDF_ONLY"
173 puts $doxyFile "GENERATE_LATEX = YES"
174 puts $doxyFile "COMPACT_LATEX = YES"
175 puts $doxyFile "PDF_HYPERLINKS = YES"
176 puts $doxyFile "USE_PDFLATEX = YES"
177 puts $doxyFile "LATEX_BATCHMODE = YES"
178 puts $doxyFile "LATEX_OUTPUT = latex"
179 puts $doxyFile "LATEX_CMD_NAME = latex"
180 puts $doxyFile "MAKEINDEX_CMD_NAME = makeindex"
181 }
182
183 close $doxyFile
184}
185
186# Returns the relative path between two directories
187proc OverviewDoc_GetRelPath {targetFile currentpath} {
188 set cc [file split [file normalize $currentpath]]
189 set tt [file split [file normalize $targetFile]]
190
191 if {![string equal [lindex $cc 0] [lindex $tt 0]]} {
192 # not on *n*x then
193 return -code error "$targetFile not on same volume as $currentpath"
194 }
195 while {[string equal [lindex $cc 0] [lindex $tt 0]] && [llength $cc] > 0} {
196 # discard matching components from the front
197 set cc [lreplace $cc 0 0]
198 set tt [lreplace $tt 0 0]
199 }
200 set prefix ""
201 if {[llength $cc] == 0} {
202 # just the file name, so targetFile is lower down (or in same place)
203 set prefix "."
204 }
205 # step up the tree
206 for {set i 0} {$i < [llength $cc]} {incr i} {
207 append prefix " .."
208 }
209 # stick it all together (the eval is to flatten the targetFile list)
210 return [eval file join $prefix $tt]
211}
212
213# Prints Help message
214proc OverviewDoc_PrintHelpMessage {} {
e5bd0d98 215 puts "\nUsage : occdoc \[-h\] \[-html\] \[-pdf\] \[-m=<list of files>\] \[-l=<document name>\] \[-v\] \[-s\]"
72b7576f 216 puts ""
217 puts " Options are : "
218 puts " -html : To generate HTML files"
8b0857f8 219 puts " (cannot be used with -pdf or -chm)"
72b7576f 220 puts " -pdf : To generate PDF files"
8b0857f8 221 puts " (cannot be used with -html or chm)"
222 puts " -chm : To generate CHM files"
223 puts " (cannot be used with -html or pdf)"
224 puts " -hhc : To define path to hhc - chm generator"
225 puts " : is used with just -chm option"
72b7576f 226 puts " -m=<modules_list> : Specifies list of documents to generate."
227 puts " If it is not specified, all files, "
228 puts " mentioned in FILES.txt are processed."
229 puts " -l=<document_name> : Specifies the document caption "
230 puts " for a single document"
231 puts " -h : Prints help message"
232 puts " -v : Specifies the Verbose mode"
233 puts " (info on all script actions is shown)"
e5bd0d98 234 puts " -s=<search_mode> : Specifies the Search mode of HTML documents."
235 puts " Can be: none | local | server | external | "
236 puts " : Can be used only with -html option"
72b7576f 237}
238
239# Parses command line arguments
240proc OverviewDoc_ParseArguments {arguments} {
241 global args_names
242 global args_values
243 set args_names {}
244 array set args_values {}
245
246 foreach arg $arguments {
247 if {[regexp {^(-)[a-z]+$} $arg] == 1} {
248 set name [string range $arg 1 [string length $arg]-1]
249 lappend args_names $name
250 set args_values($name) "NULL"
251 continue
252 } elseif {[regexp {^(-)[a-z]+=.+$} $arg] == 1} {
253 set equal_symbol_position [string first "=" $arg]
254 set name [string range $arg 1 $equal_symbol_position-1]
255 lappend args_names $name
256 set value [string range $arg $equal_symbol_position+1 [string length $arguments]-1]
257
258 # To parse a list of values for -m parameter
259 if { [string first "," $value] != -1 } {
260 set value [split $value ","];
261 }
262 set args_values($name) $value
263 } else {
264 puts "Error in argument $arg"
265 return 1
266 }
267 }
268 return 0
269}
270
271# Loads a list of docfiles from file FILES.txt
272proc OverviewDoc_LoadFilesList {} {
273
274 set INPUTDIR [file normalize [file dirname [info script]]]
275
276 global available_docfiles
277 set available_docfiles {}
278
279 # Read data from file
280 if { [file exists "$INPUTDIR/FILES.txt"] == 1 } {
281 set FILE [open "$INPUTDIR/FILES.txt" r]
282 while {1} {
e5bd0d98 283 set line [string trim [gets $FILE]]
284
285 # trim possible comments starting with '#'
286 set line [regsub {\#.*} $line {}]
287
72b7576f 288 if {$line != ""} {
289 lappend available_docfiles $line
290 }
291
292 if {[eof $FILE]} {
293 close $FILE
294 break
295 }
296 }
297 } else {
298 return -1
299 }
300 return 0
301}
302
303# Writes new tex file for conversion from tex to pdf for a specific doc
304proc OverviewDoc_MakeRefmanTex {fileName latexDir docLabel verboseMode} {
305
306 if {$verboseMode == "YES"} {
307 puts "INFO: Making refman.tex file for $fileName"
308 }
309 set DOCNAME "$latexDir/refman.tex"
310 if {[file exists $DOCNAME] == 1} {
311 file delete -force $DOCNAME
312 }
313 set texfile [open $DOCNAME w]
314
315 puts $texfile "\\batchmode"
316 puts $texfile "\\nonstopmode"
317 puts $texfile "\\documentclass\[oneside\]{article}"
318 puts $texfile "\n% Packages required by doxygen"
319 puts $texfile "\\usepackage{calc}"
320 puts $texfile "\\usepackage{doxygen}"
321 puts $texfile "\\usepackage{graphicx}"
322 puts $texfile "\\usepackage\[utf8\]{inputenc}"
323 puts $texfile "\\usepackage{makeidx}"
324 puts $texfile "\\usepackage{multicol}"
325 puts $texfile "\\usepackage{multirow}"
326 puts $texfile "\\usepackage{textcomp}"
327 puts $texfile "\\usepackage{amsmath}"
328 puts $texfile "\\usepackage\[table\]{xcolor}"
329 puts $texfile "\\usepackage{indentfirst}"
330 puts $texfile ""
331 puts $texfile "% Font selection"
332 puts $texfile "\\usepackage\[T1\]{fontenc}"
333 puts $texfile "\\usepackage{mathptmx}"
334 puts $texfile "\\usepackage\[scaled=.90\]{helvet}"
335 puts $texfile "\\usepackage{courier}"
336 puts $texfile "\\usepackage{amssymb}"
337 puts $texfile "\\usepackage{sectsty}"
338 puts $texfile "\\renewcommand{\\familydefault}{\\sfdefault}"
339 puts $texfile "\\allsectionsfont{%"
340 puts $texfile " \\fontseries{bc}\\selectfont%"
341 puts $texfile " \\color{darkgray}%"
342 puts $texfile "}"
343 puts $texfile "\\renewcommand{\\DoxyLabelFont}{%"
344 puts $texfile " \\fontseries{bc}\\selectfont%"
345 puts $texfile " \\color{darkgray}%"
346 puts $texfile "}"
347 puts $texfile ""
348 puts $texfile "% Page & text layout"
349 puts $texfile "\\usepackage{geometry}"
350 puts $texfile "\\geometry{%"
351 puts $texfile " a4paper,%"
352 puts $texfile " top=2.5cm,%"
353 puts $texfile " bottom=2.5cm,%"
354 puts $texfile " left=2.5cm,%"
355 puts $texfile " right=2.5cm%"
356 puts $texfile "}"
357 puts $texfile "\\tolerance=750"
358 puts $texfile "\\hfuzz=15pt"
359 puts $texfile "\\hbadness=750"
360 puts $texfile "\\setlength{\\emergencystretch}{15pt}"
e5bd0d98 361 puts $texfile "\\setlength{\\parindent}{0cm}";#0.75cm
362 puts $texfile "\\setlength{\\parskip}{0.2cm}"; #0.2
72b7576f 363 puts $texfile "\\makeatletter"
364 puts $texfile "\\renewcommand{\\paragraph}{%"
365 puts $texfile " \@startsection{paragraph}{4}{0ex}{-1.0ex}{1.0ex}{%"
366 puts $texfile "\\normalfont\\normalsize\\bfseries\\SS@parafont%"
367 puts $texfile " }%"
368 puts $texfile "}"
369 puts $texfile "\\renewcommand{\\subparagraph}{%"
370 puts $texfile " \\@startsection{subparagraph}{5}{0ex}{-1.0ex}{1.0ex}{%"
371 puts $texfile "\\normalfont\\normalsize\\bfseries\\SS@subparafont%"
372 puts $texfile " }%"
373 puts $texfile "}"
374 puts $texfile "\\makeatother"
375 puts $texfile ""
376 puts $texfile "% Headers & footers"
377 puts $texfile "\\usepackage{fancyhdr}"
378 puts $texfile "\\pagestyle{fancyplain}"
379 puts $texfile "\\fancyhead\[LE\]{\\fancyplain{}{\\bfseries\\thepage}}"
380 puts $texfile "\\fancyhead\[CE\]{\\fancyplain{}{}}"
381 puts $texfile "\\fancyhead\[RE\]{\\fancyplain{}{\\bfseries\\leftmark}}"
382 puts $texfile "\\fancyhead\[LO\]{\\fancyplain{}{\\bfseries\\rightmark}}"
383 puts $texfile "\\fancyhead\[CO\]{\\fancyplain{}{}}"
384 puts $texfile "\\fancyhead\[RO\]{\\fancyplain{}{\\bfseries\\thepage}}"
385 puts $texfile "\\fancyfoot\[LE\]{\\fancyplain{}{}}"
386 puts $texfile "\\fancyfoot\[CE\]{\\fancyplain{}{}}"
e5bd0d98 387 puts $texfile "\\fancyfoot\[RE\]{\\fancyplain{}{\\bfseries\\scriptsize (c) Open CASCADE 2001\-2013}}"
388 puts $texfile "\\fancyfoot\[LO\]{\\fancyplain{}{\\bfseries\\scriptsize (c) Open CASCADE 2001\-2013}}"
72b7576f 389 puts $texfile "\\fancyfoot\[CO\]{\\fancyplain{}{}}"
390 puts $texfile "\\fancyfoot\[RO\]{\\fancyplain{}{}}"
391 puts $texfile "\\renewcommand{\\footrulewidth}{0.4pt}"
392 puts $texfile "\\renewcommand{\\sectionmark}\[1\]{%"
393 puts $texfile " \\markright{\\thesection\\ #1}%"
394 puts $texfile "}"
395 puts $texfile ""
396 puts $texfile "% Indices & bibliography"
397 puts $texfile "\\usepackage{natbib}"
398 puts $texfile "\\usepackage\[titles\]{tocloft}"
399 puts $texfile "\\renewcommand{\\cftsecleader}{\\cftdotfill{\\cftdotsep}}"
400 puts $texfile "\\setcounter{tocdepth}{3}"
401 puts $texfile "\\setcounter{secnumdepth}{5}"
402 puts $texfile "\\makeindex"
403 puts $texfile ""
404 puts $texfile "% Hyperlinks (required, but should be loaded last)"
405 puts $texfile "\\usepackage{ifpdf}"
406 puts $texfile "\\ifpdf"
407 puts $texfile " \\usepackage\[pdftex,pagebackref=true\]{hyperref}"
408 puts $texfile "\\else"
409 puts $texfile " \\usepackage\[ps2pdf,pagebackref=true\]{hyperref}"
410 puts $texfile "\\fi"
411 puts $texfile "\\hypersetup{%"
412 puts $texfile " colorlinks=true,%"
413 puts $texfile " linkcolor=black,%"
414 puts $texfile " citecolor=black,%"
415 puts $texfile " urlcolor=blue,%"
416 puts $texfile " unicode%"
417 puts $texfile "}"
418 puts $texfile ""
419 puts $texfile "% Custom commands"
420 puts $texfile "\\newcommand{\\clearemptydoublepage}{%"
421 puts $texfile " \\newpage{\\pagestyle{empty}\\cleardoublepage}%"
422 puts $texfile "}"
423 puts $texfile "\n"
424 puts $texfile "%===== C O N T E N T S =====\n"
425 puts $texfile "\\begin{document}"
426 puts $texfile ""
427 puts $texfile "% Titlepage & ToC"
428 puts $texfile "\\hypersetup{pageanchor=false}"
429 puts $texfile "\\pagenumbering{roman}"
430 puts $texfile "\\begin{titlepage}"
431 puts $texfile "\\vspace*{7cm}"
432 puts $texfile "\\begin{center}%"
e5bd0d98 433 puts $texfile "\\includegraphics\[width=0.75\\textwidth, height=0.2\\textheight\]{../../../dox/resources/occt_logo.png}\\\\"; #\\\\\\\\
434 puts $texfile "{\\Large Open C\\-A\\-S\\-C\\-A\\-D\\-E Technology \\\\\[1ex\]\\Large [OverviewDoc_DetectCasVersion $latexDir/../../../] }\\\\"
72b7576f 435 puts $texfile "\\vspace*{1cm}"
436 puts $texfile "{\\Large $docLabel}\\\\"
437 puts $texfile "\\vspace*{1cm}"
438 puts $texfile "{\\large Generated by Doxygen 1.8.4}\\\\"
439 puts $texfile "\\vspace*{0.5cm}"
440 puts $texfile "{\\small \\today}\\"
441 puts $texfile "\\end{center}"
442 puts $texfile "\\end{titlepage}"
443 puts $texfile "\\clearpage"
444 puts $texfile "\\pagenumbering{roman}"
445 puts $texfile "\\tableofcontents"
446 puts $texfile "\\newpage"
447 puts $texfile "\\pagenumbering{arabic}"
448 puts $texfile "\\hypersetup{pageanchor=true}"
449 puts $texfile ""
e5bd0d98 450 puts $texfile "\\let\\stdsection\\section"
451 puts $texfile " \\renewcommand\\section{\\pagebreak\\stdsection}"
72b7576f 452 puts $texfile "\\hypertarget{$fileName}{}"
453 puts $texfile "\\input{$fileName}"
454 puts $texfile ""
455 puts $texfile "% Index"
456 puts $texfile "\\newpage"
457 puts $texfile "\\phantomsection"
458 puts $texfile "\\addcontentsline{toc}{part}{Index}"
459 puts $texfile "\\printindex\n"
460 puts $texfile "\\end{document}"
461
462 close $texfile
463}
464
465# Postprocesses generated TeX files
466proc OverviewDoc_ProcessTex {{texFiles {}} {latexDir} verboseMode} {
467
468 foreach TEX $texFiles {
469 if {$verboseMode == "YES"} {
470 puts "INFO: Preprocessing file $TEX"
471 }
dba69de2 472
473 if {![file exists $TEX]} {
474 puts "file $TEX doesn't exist"
475 return
476 }
477
72b7576f 478 set IN_F [open "$TEX" r]
479 set TMPFILENAME "$latexDir/temp.tex"
dba69de2 480
72b7576f 481 set OUT_F [open $TMPFILENAME w]
482
483 while {1} {
484 set line [gets $IN_F]
485 if { [string first "\\includegraphics" $line] != -1 } {
486 # Center images in TeX files
487 set line "\\begin{center}\n $line\n\\end{center}"
488 } elseif { [string first "\\subsection" $line] != -1 } {
489 # Replace \subsection with \section tag
490 regsub -all "\\\\subsection" $line "\\\\section" line
491 } elseif { [string first "\\subsubsection" $line] != -1 } {
492 # Replace \subsubsection with \subsection tag
493 regsub -all "\\\\subsubsection" $line "\\\\subsection" line
494 } elseif { [string first "\\paragraph" $line] != -1 } {
495 # Replace \paragraph with \subsubsection tag
496 regsub -all "\\\\paragraph" $line "\\\\subsubsection" line
497 }
498 puts $OUT_F $line
499
500 if {[eof $IN_F]} {
501 close $IN_F
502 close $OUT_F
503 break
504 }
505 }
506 file delete -force $TEX
507 file rename $TMPFILENAME $TEX
508 }
509}
510
511# Main procedure for documents compilation
8b0857f8 512proc OverviewDoc_Main { {docfiles {}} generatorMode docLabel verboseMode searchMode hhcPath} {
72b7576f 513
514 set INDIR [file normalize [file dirname [info script]]]
515 set CASROOT [file normalize [file dirname "$INDIR/../../"]]
516 set OUTDIR $CASROOT/doc
517 set PDFDIR $OUTDIR/overview/pdf
518 set HTMLDIR $OUTDIR/overview/html
519 set LATEXDIR $OUTDIR/overview/latex
520 set TAGFILEDIR $OUTDIR/refman
521 set DOXYFILE $OUTDIR/OCCT.cfg
522
523 # Create or clean the output folders
524 if {[file exists $OUTDIR] == 0} {
525 file mkdir $OUTDIR
526 }
527 if {[file exists $HTMLDIR] == 0} {
528 file mkdir $HTMLDIR
529 }
72b7576f 530 if {[file exists $PDFDIR] == 0} {
531 file mkdir $PDFDIR
532 }
e5bd0d98 533
534 if {[file exists $LATEXDIR]} {
535 #file delete {*}[glob -nocomplain $LATEXDIR/*.*]
536 file delete -force $LATEXDIR
537 }
538 file mkdir $LATEXDIR
72b7576f 539
540 # Run tools to compile documents
e5bd0d98 541 puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generating Doxyfile..."
542
8b0857f8 543 OverviewDoc_MakeDoxyfile $CASROOT "$OUTDIR/overview" $TAGFILEDIR $DOXYFILE $generatorMode $docfiles $verboseMode $searchMode $hhcPath
72b7576f 544
545 # Run doxygen tool
546 if { $generatorMode == "HTML_ONLY"} {
8b0857f8 547 puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generating HTML files..."
548 } elseif { $generatorMode == "CHM_ONLY" } {
549 puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generating CHM file..."
72b7576f 550 }
551 set RESULT [catch {exec doxygen $DOXYFILE > $OUTDIR/doxygen_out.log} DOX_ERROR]
552 if {$RESULT != 0} {
553 if {[llength [split $DOX_ERROR "\n"]] > 1} {
554 if {$verboseMode == "YES"} {
e5bd0d98 555 puts "See Doxygen log in $OUTDIR/doxygen_warnings_and_errors.log"
72b7576f 556 }
557 set DOX_ERROR_FILE [open "$OUTDIR/doxygen_warnings_and_errors.log" "w"]
558 puts $DOX_ERROR_FILE $DOX_ERROR
559 close $DOX_ERROR_FILE
560 } else {
561 puts $DOX_ERROR
562 }
563 }
564 # Close the Doxygen application
565 after 300
566
567 # Start PDF generation routine
568 if { $generatorMode == "PDF_ONLY" } {
e5bd0d98 569 puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generating PDF files..."
72b7576f 570
571 set OS $::tcl_platform(platform)
572 if { $OS == "unix" } {
573 set PREFIX ".sh"
574 } elseif { $OS == "windows" } {
575 set PREFIX ".bat"
576 }
577
578 # Prepare a list of TeX files, generated by Doxygen
579 cd $LATEXDIR
580
581 set TEXFILES [glob $LATEXDIR -type f -directory $LATEXDIR -tails "*.tex" ]
582 set REFMAN_IDX [lsearch $TEXFILES "refman.tex"]
583 set TEXFILES [lreplace $TEXFILES $REFMAN_IDX $REFMAN_IDX]
dba69de2 584
72b7576f 585
586 set IDX [lsearch $TEXFILES "$LATEXDIR"]
587 while { $IDX != -1} {
588 set TEXFILES [lreplace $TEXFILES $IDX $IDX]
589 set IDX [lsearch $TEXFILES "$LATEXDIR"]
590 }
591
e5bd0d98 592 if {$verboseMode == "YES"} {
593 puts "Preprocessing generated TeX files..."
594 }
72b7576f 595 OverviewDoc_ProcessTex $TEXFILES $LATEXDIR $verboseMode
e5bd0d98 596
597 if {$verboseMode == "YES"} {
598 puts "Generating PDF files from TeX files..."
599 }
72b7576f 600 foreach TEX $TEXFILES {
601 # Rewrite existing REFMAN.tex file...
602 set TEX [string range $TEX 0 [ expr "[string length $TEX] - 5"]]
603 OverviewDoc_MakeRefmanTex $TEX $LATEXDIR $docLabel $verboseMode
604
605 if {$verboseMode == "YES"} {
606 puts "INFO: Generating PDF file from $TEX"
e5bd0d98 607 # ...and use it to generate PDF from TeX...
608 puts "Executing $LATEXDIR/make$PREFIX..."
72b7576f 609 }
72b7576f 610 set RESULT [catch {eval exec [auto_execok $LATEXDIR/make$PREFIX] > "$OUTDIR/pdflatex_out.log"} LaTeX_ERROR]
611 if {$RESULT != 0} {
612 if {[llength [split $LaTeX_ERROR "\n"]] > 1} {
e5bd0d98 613 if {$verboseMode == "YES"} {
614 puts "See Latex log in $OUTDIR/pdflatex_warnings_and_errors.log"
615 }
72b7576f 616 set LaTeX_ERROR_FILE [open "$OUTDIR/pdflatex_warnings_and_errors.log" "w"]
617 puts $LaTeX_ERROR_FILE $LaTeX_ERROR
618 close $LaTeX_ERROR_FILE
619 } else {
620 puts $DOX_ERROR
621 }
622 }
623
624 # ...and place it to the specific folder
625 if { [file exists $PDFDIR/$TEX.pdf] == 1 } {
626 file delete -force $PDFDIR/$TEX.pdf
627 }
dba69de2 628
629 if {![file exists "$LATEXDIR/refman.pdf"]} {
e5bd0d98 630 puts "Error: file $LATEXDIR/refman.pdf does not exist"
dba69de2 631 return
632 }
633
72b7576f 634 file rename $LATEXDIR/refman.pdf "$PDFDIR/$TEX.pdf"
635 }
72b7576f 636 }
637
638 cd $INDIR
e5bd0d98 639 puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generation completed"
72b7576f 640 if { $generatorMode == "HTML_ONLY" } {
e5bd0d98 641 puts "View generated HTML documentation by opening: "
72b7576f 642 set RESFILE $OUTDIR/overview/html/index.html
e5bd0d98 643 puts "$RESFILE"
72b7576f 644 }
645 if { $generatorMode == "PDF_ONLY" } {
e5bd0d98 646 puts "PDF files are generated in: "
647 puts "$OUTDIR/overview/pdf folder"
72b7576f 648 }
72b7576f 649}
650
651# A command for User Documentation compilation
652proc occdoc {args} {
653 # Programm options
e5bd0d98 654 set GEN_MODE "HTML_ONLY"
655
72b7576f 656 set DOCFILES {}
e5bd0d98 657 set DOCLABEL "Default OCCT Document"
658 set VERB_MODE "NO"
659 set SEARCH_MODE "none"
8b0857f8 660 set hhcPath ""
e5bd0d98 661
72b7576f 662 global available_docfiles
8b0857f8 663 global tcl_platform
72b7576f 664 global args_names
665 global args_values
8b0857f8 666 global env
72b7576f 667
668 # Load list of docfiles
669 if { [OverviewDoc_LoadFilesList] != 0 } {
670 puts "ERROR: File FILES.txt was not found"
671 return
672 }
673
674 # Parse CL arguments
675 if {[OverviewDoc_ParseArguments $args] == 1} {
676 return
677 }
8b0857f8 678
679 foreach arg_n $args_names {
e5bd0d98 680 if {$arg_n == "h"} {
681 OverviewDoc_PrintHelpMessage
682 return
683 } elseif {$arg_n == "html"} {
72b7576f 684 set GEN_MODE "HTML_ONLY"
8b0857f8 685 } elseif {$arg_n == "chm"} {
686 set GEN_MODE "CHM_ONLY"
687
688 if {"$tcl_platform(platform)" == "windows" && [lsearch $args_names hhc] == -1} {
689 if { [info exist env(ProgramFiles\(x86\))] } {
690 set hhcPath "$env(ProgramFiles\(x86\))\\HTML Help Workshop\\hhc.exe"
691 puts "Info: hhc found: $hhcPath"
692 } elseif { [info exist env(ProgramFiles)] } {
693 set hhcPath "$env(ProgramFiles)\\HTML Help Workshop\\hhc.exe"
694 puts "Info: hhc found: $hhcPath"
695 }
696
697 if { ! [file exists $hhcPath] } {
698 puts "Error: HTML Help Compiler is not found in standard location [file dirname $hhcPath]; use option -hhc"
699 return
700 }
701 }
702
703 } elseif {$arg_n == "hhc"} {
704 global tcl_platform
705 if { $tcl_platform(platform) != "windows" } {
706 continue
707 }
708
709 if {$args_values(hhc) != "NULL"} {
710 set hhcPath $args_values(hhc)
711 if { [file isdirectory $hhcPath] } {
712 set hhcPath [file join ${hhcPath} hhc.exe]
713 }
714 if { ! [file exists $hhcPath] } {
715 puts "Error: HTML Help Compiler is not found in $hhcPath"
716 return
717 }
718 } else {
719 puts "Error in argument hhc"
720 return
721 }
722
e5bd0d98 723 } elseif {$arg_n == "pdf"} {
72b7576f 724 set GEN_MODE "PDF_ONLY"
e5bd0d98 725 } elseif {$arg_n == "v"} {
726 set VERB_MODE "YES"
727 } elseif {$arg_n == "m"} {
728 if {$args_values(m) != "NULL"} {
729 set DOCFILES $args_values(m)
730 } else {
731 puts "Error in argument m"
732 return
733 }
8b0857f8 734
e5bd0d98 735 # Check if all chosen docfiles are correct
736 foreach docfile $DOCFILES {
737 if { [lsearch $available_docfiles $docfile] == -1 } {
738 puts "File \"$docfile\" is not presented in the list of available docfiles"
739 puts "Please, specify the correct docfile name"
740 return
741 } else {
742 puts "File $docfile is presented in FILES.TXT"
743 }
744 }
745 } elseif {$arg_n == "l"} {
746 if { [llength $DOCFILES] <= 1 } {
747 if {$args_values(l) != "NULL"} {
748 set DOCLABEL $args_values(l)
749 } else {
750 puts "Error in argument l"
751 return
72b7576f 752 }
e5bd0d98 753 }
754 } elseif {$arg_n == "s"} {
755 if {$args_values(s) != "NULL"} {
756 set SEARCH_MODE $args_values(s)
757 } else {
758 puts "Error in argument s"
72b7576f 759 return
e5bd0d98 760 }
761 } else {
762 puts "\nWrong argument: $arg_n"
763 OverviewDoc_PrintHelpMessage
764 return
72b7576f 765 }
e5bd0d98 766 }
767
768 # Specify verbose mode
769 if { $GEN_MODE != "PDF_ONLY" && [llength $DOCFILES] > 1 } {
770 set DOCLABEL ""
771 }
72b7576f 772
e5bd0d98 773 # If we don't specify list for docfiles with -m argument,
774 # we assume that we have to generate all docfiles
775 if { [llength $DOCFILES] == 0 } {
776 set DOCFILES $available_docfiles
777 }
72b7576f 778
e5bd0d98 779 # Start main activities
8b0857f8 780 OverviewDoc_Main $DOCFILES $GEN_MODE $DOCLABEL $VERB_MODE $SEARCH_MODE $hhcPath
72b7576f 781}