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