| 1 | # ======================================================================= |
| 2 | # Created on: 2014-03-21 |
| 3 | # Created by: OMY |
| 4 | # Copyright (c) 1996-1999 Matra Datavision |
| 5 | # Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 6 | # |
| 7 | # This file is part of Open CASCADE Technology software library. |
| 8 | # |
| 9 | # This library is free software; you can redistribute it and/or modify it under |
| 10 | # the terms of the GNU Lesser General Public License version 2.1 as published |
| 11 | # by the Free Software Foundation, with special exception defined in the file |
| 12 | # OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 13 | # distribution for complete text of the license and disclaimer of any warranty. |
| 14 | # |
| 15 | # Alternatively, this file may be used under the terms of Open CASCADE |
| 16 | # commercial license or contractual agreement. |
| 17 | # |
| 18 | # Brief: This script contains auxilary functions which can be used |
| 19 | # in documentation generation process |
| 20 | # ======================================================================= |
| 21 | |
| 22 | # ============================================== |
| 23 | # Commonly used functions |
| 24 | # ============================================== |
| 25 | |
| 26 | # Parses arguments line like "-arg1=val1 -arg2=val2 ..." to array args_names and map args_values |
| 27 | proc OCCDoc_ParseArguments {arguments} { |
| 28 | global args_names |
| 29 | global args_values |
| 30 | set args_names {} |
| 31 | array set args_values {} |
| 32 | |
| 33 | foreach arg $arguments { |
| 34 | if {[regexp {^(-)[a-z]+$} $arg] == 1} { |
| 35 | set name [string range $arg 1 [string length $arg]-1] |
| 36 | lappend args_names $name |
| 37 | set args_values($name) "NULL" |
| 38 | continue |
| 39 | } elseif {[regexp {^(-)[a-z]+=.+$} $arg] == 1} { |
| 40 | set equal_symbol_position [string first "=" $arg] |
| 41 | set name [string range $arg 1 $equal_symbol_position-1] |
| 42 | lappend args_names $name |
| 43 | set value [string range $arg $equal_symbol_position+1 [string length $arguments]-1] |
| 44 | |
| 45 | # To parse a list of values for -m parameter |
| 46 | if { [string first "," $value] != -1 } { |
| 47 | set value [split $value ","]; |
| 48 | } |
| 49 | |
| 50 | set args_values($name) $value |
| 51 | |
| 52 | } else { |
| 53 | puts "Error in argument $arg." |
| 54 | return 1 |
| 55 | } |
| 56 | } |
| 57 | return 0 |
| 58 | } |
| 59 | |
| 60 | # Returns script parent folder |
| 61 | proc OCCDoc_GetDoxDir {} { |
| 62 | return [file normalize [file dirname [info script]]/../dox] |
| 63 | } |
| 64 | |
| 65 | # Returns OCCT root dir |
| 66 | proc OCCDoc_GetOCCTRootDir {} { |
| 67 | set path [OCCDoc_GetDoxDir] |
| 68 | return [file normalize $path/..] |
| 69 | } |
| 70 | |
| 71 | # Returns root dir |
| 72 | proc OCCDoc_GetRootDir { {theProductsPath ""} } { |
| 73 | |
| 74 | if { $theProductsPath == "" } { |
| 75 | return [OCCDoc_GetOCCTRootDir] |
| 76 | } else { |
| 77 | return [file normalize $theProductsPath] |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | # Returns OCCT include dir |
| 82 | proc OCCDoc_GetIncDir { {theProductsPath ""} } { |
| 83 | set path [OCCDoc_GetRootDir $theProductsPath] |
| 84 | return "$path/inc" |
| 85 | } |
| 86 | |
| 87 | # Returns OCCT source dir |
| 88 | proc OCCDoc_GetSourceDir { {theProductsPath ""} } { |
| 89 | set path [OCCDoc_GetRootDir $theProductsPath] |
| 90 | return "$path/src" |
| 91 | } |
| 92 | |
| 93 | # Returns name of the package from the current toolkit |
| 94 | proc OCCDoc_GetNameFromPath { thePath } { |
| 95 | |
| 96 | set splitted_path [split $thePath "/" ] |
| 97 | set package_name [lindex $splitted_path end] |
| 98 | |
| 99 | return $package_name |
| 100 | } |
| 101 | |
| 102 | # Returns the relative path between two folders |
| 103 | proc OCCDoc_GetRelPath {thePathFrom thePathTo} { |
| 104 | if { [file isdirectory "$thePathFrom"] == 0 } { |
| 105 | return "" |
| 106 | } |
| 107 | |
| 108 | set aPathFrom [file normalize "$thePathFrom"] |
| 109 | set aPathTo [file normalize "$thePathTo"] |
| 110 | |
| 111 | set aCutedPathFrom "${aPathFrom}/dummy" |
| 112 | set aRelatedDeepPath "" |
| 113 | |
| 114 | while { "$aCutedPathFrom" != [file normalize "$aCutedPathFrom/.."] } { |
| 115 | set aCutedPathFrom [file normalize "$aCutedPathFrom/.."] |
| 116 | # does aPathTo contain aCutedPathFrom? |
| 117 | regsub -all $aCutedPathFrom $aPathTo "" aPathFromAfterCut |
| 118 | if { "$aPathFromAfterCut" != "$aPathTo" } { # if so |
| 119 | if { "$aCutedPathFrom" == "$aPathFrom" } { # just go higher, for example, ./somefolder/someotherfolder |
| 120 | set aPathTo ".${aPathTo}" |
| 121 | } elseif { "$aCutedPathFrom" == "$aPathTo" } { # remove the last "/" |
| 122 | set aRelatedDeepPath [string replace $aRelatedDeepPath end end ""] |
| 123 | } |
| 124 | regsub -all $aCutedPathFrom $aPathTo $aRelatedDeepPath aPathToAfterCut |
| 125 | regsub -all "//" $aPathToAfterCut "/" aPathToAfterCut |
| 126 | return $aPathToAfterCut |
| 127 | } |
| 128 | set aRelatedDeepPath "$aRelatedDeepPath../" |
| 129 | } |
| 130 | |
| 131 | return $thePathTo |
| 132 | } |
| 133 | |
| 134 | # Returns OCCT version string from file Standard_Version.hxx (if available) |
| 135 | proc OCCDoc_DetectCasVersion {} { |
| 136 | set occt_ver 6.7.0 |
| 137 | set occt_ver_add "" |
| 138 | set filename "[OCCDoc_GetSourceDir]/Standard/Standard_Version.hxx" |
| 139 | if { [file exists $filename] } { |
| 140 | set fh [open $filename "r"] |
| 141 | set fh_loaded [read $fh] |
| 142 | close $fh |
| 143 | regexp {[^/]\s*#\s*define\s+OCC_VERSION_COMPLETE\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver |
| 144 | regexp {[^/]\s*#\s*define\s+OCC_VERSION_DEVELOPMENT\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver_add |
| 145 | if { "$occt_ver_add" != "" } { set occt_ver ${occt_ver}.$occt_ver_add } |
| 146 | } |
| 147 | return $occt_ver |
| 148 | } |
| 149 | |
| 150 | # Checks if the necessary tools exist |
| 151 | proc OCCDoc_DetectNecessarySoftware { DOXYGEN_PATH GRAPHVIZ_PATH INKSCAPE_PATH HHC_PATH PDFLATEX_PATH } { |
| 152 | |
| 153 | upvar 1 DOXYGEN_PATH doxy_path |
| 154 | upvar 1 GRAPHVIZ_PATH graph_path |
| 155 | upvar 1 INKSCAPE_PATH inkscape_path |
| 156 | upvar 1 HHC_PATH hhc_path |
| 157 | upvar 1 PDFLATEX_PATH latex_path |
| 158 | |
| 159 | set doxy_path "" |
| 160 | set graph_path "" |
| 161 | set inkscape_path "" |
| 162 | set latex_path "" |
| 163 | set hhc_path "" |
| 164 | |
| 165 | set is_win "no" |
| 166 | if { "$::tcl_platform(platform)" == "windows" } { |
| 167 | set is_win "yes" |
| 168 | } |
| 169 | if {"$is_win" == "yes"} { |
| 170 | set exe ".exe" |
| 171 | } else { |
| 172 | set exe "" |
| 173 | } |
| 174 | |
| 175 | set g_flag "no" |
| 176 | set d_flag "no" |
| 177 | set i_flag "no" |
| 178 | set h_flag "no" |
| 179 | set l_flag "no" |
| 180 | |
| 181 | puts "" |
| 182 | set envPath $::env(PATH) |
| 183 | if { $is_win == "yes" } { |
| 184 | set searchPathsList [split $envPath ";"] |
| 185 | } else { |
| 186 | set searchPathsList [split $envPath ":"] |
| 187 | } |
| 188 | |
| 189 | foreach path $searchPathsList { |
| 190 | if { ($is_win == "no") && |
| 191 | (($path == "/usr/bin") || ($path == "/usr/local/bin")) } { |
| 192 | # Avoid searching in default bin location |
| 193 | continue |
| 194 | } |
| 195 | if {$d_flag == "no"} { |
| 196 | if { [file exists $path/doxygen$exe] } { |
| 197 | catch { exec $path/doxygen -V } version_string |
| 198 | set version [lindex [split $version_string "\n"] 0] |
| 199 | puts "Info: $version " |
| 200 | puts " found in $path." |
| 201 | set doxy_path "$path/doxygen$exe" |
| 202 | set d_flag "yes" |
| 203 | } |
| 204 | } |
| 205 | if {$g_flag == "no"} { |
| 206 | if { [file exists $path/dot$exe] } { |
| 207 | catch { exec $path/dot -V } version |
| 208 | |
| 209 | puts "Info: $version " |
| 210 | puts " found in $path." |
| 211 | set graph_path "$path/dot$exe" |
| 212 | set g_flag "yes" |
| 213 | } |
| 214 | } |
| 215 | if {$i_flag == "no"} { |
| 216 | if { [file exists $path/inkscape$exe] } { |
| 217 | catch { exec $path/inkscape -V } version |
| 218 | puts "Info: $version " |
| 219 | puts " found in $path." |
| 220 | set inkscape_path "$path/inkscape$exe" |
| 221 | set i_flag "yes" |
| 222 | } |
| 223 | } |
| 224 | if {$l_flag == "no"} { |
| 225 | if { [file exists $path/pdflatex$exe] } { |
| 226 | catch { exec $path/pdflatex -version } version |
| 227 | set version [lindex [split $version "\n"] 0] |
| 228 | puts "Info: $version " |
| 229 | puts " found in $path." |
| 230 | set latex_path "$path/pdflatex$exe" |
| 231 | set l_flag "yes" |
| 232 | } |
| 233 | } |
| 234 | if { ("$is_win" == "yes") && ($h_flag == "no") } { |
| 235 | if { [file exists $path/hhc.exe] } { |
| 236 | puts "Info: hhc " |
| 237 | puts " found in $path." |
| 238 | set hhc_path "hhc$exe" |
| 239 | set h_flag "yes" |
| 240 | } |
| 241 | } |
| 242 | if { ($d_flag == "yes") && |
| 243 | ($i_flag == "yes") && |
| 244 | ($g_flag == "yes") && |
| 245 | ($l_flag == "yes") && |
| 246 | (($is_win == "yes") && |
| 247 | ($h_flag == "yes")) } { |
| 248 | break |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | # On Windows search for hhc.exe in the default location |
| 253 | # if it has not been found yet |
| 254 | if { ("$is_win" == "yes") && ($h_flag == "no") } { |
| 255 | if { [info exists ::env(ProgramFiles\(x86\))] } { |
| 256 | set h_flag "yes" |
| 257 | set path "$::env(ProgramFiles\(x86\))\\HTML Help Workshop" |
| 258 | set hhc_path "$path\\hhc.exe" |
| 259 | puts "Info: hhc " |
| 260 | puts " found in $path." |
| 261 | } else { |
| 262 | if { [info exists ::env(ProgramFiles)] } { |
| 263 | set h_flag "yes" |
| 264 | set path "$::env(ProgramFiles)\\HTML Help Workshop" |
| 265 | set hhc_path "$path\\hhc.exe" |
| 266 | puts "Info: hhc" |
| 267 | puts " found in $path." |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | # On *nix-like platforms, |
| 273 | # check the default binary locations if the tools had not been found yet |
| 274 | if { $is_win == "no" && |
| 275 | (($d_flag == "no") || |
| 276 | ($i_flag == "no") || |
| 277 | ($g_flag == "no") || |
| 278 | ($l_flag == "no")) } { |
| 279 | |
| 280 | set default_path { "/usr/bin" "/usr/local/bin" } |
| 281 | foreach path $default_path { |
| 282 | if {$d_flag == "no"} { |
| 283 | if { [file exists $path/doxygen$exe] } { |
| 284 | catch { exec $path/doxygen -V } version_string |
| 285 | set version [lindex [split $version_string "\n"] 0] |
| 286 | puts "Info: $version " |
| 287 | puts " found in $path." |
| 288 | set doxy_path "$path/doxygen$exe" |
| 289 | set d_flag "yes" |
| 290 | } |
| 291 | } |
| 292 | if {$g_flag == "no"} { |
| 293 | if { [file exists $path/dot$exe] } { |
| 294 | catch { exec $path/dot -V } version |
| 295 | |
| 296 | puts "Info: $version " |
| 297 | puts " found in $path." |
| 298 | set graph_path "$path/dot$exe" |
| 299 | set g_flag "yes" |
| 300 | } |
| 301 | } |
| 302 | if {$i_flag == "no"} { |
| 303 | if { [file exists $path/inkscape$exe] } { |
| 304 | catch { exec $path/inkscape -V } version |
| 305 | puts "Info: $version " |
| 306 | puts " found in $path." |
| 307 | set inkscape_path "$path/inkscape$exe" |
| 308 | set i_flag "yes" |
| 309 | } |
| 310 | } |
| 311 | if {$l_flag == "no"} { |
| 312 | if { [file exists $path/pdflatex$exe] } { |
| 313 | catch { exec $path/pdflatex -version } version |
| 314 | set version [lindex [split $version "\n"] 0] |
| 315 | puts "Info: $version " |
| 316 | puts " found in $path." |
| 317 | set latex_path "$path/pdflatex$exe" |
| 318 | set l_flag "yes" |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | # Check if tools have been found |
| 325 | if { $d_flag == "no" } { |
| 326 | puts "Warning: Could not find doxygen installed." |
| 327 | return -1 |
| 328 | } |
| 329 | if { $g_flag == "no" } { |
| 330 | puts "Warning: Could not find graphviz installed." |
| 331 | } |
| 332 | if { $i_flag == "no" } { |
| 333 | puts "Warning: Could not find inkscape installed." |
| 334 | } |
| 335 | if { $l_flag == "no" } { |
| 336 | puts "Warning: Could not find pdflatex installed." |
| 337 | } |
| 338 | if { ("$::tcl_platform(platform)" == "windows") && ($h_flag == "no") } { |
| 339 | puts "Warning: Could not find hhc installed." |
| 340 | } |
| 341 | |
| 342 | puts "" |
| 343 | } |
| 344 | |
| 345 | # Convert SVG files to PDF format to allow including them to PDF |
| 346 | # (requires InkScape to be in PATH) |
| 347 | proc OCCDoc_ProcessSvg {latexDir verboseMode} { |
| 348 | |
| 349 | foreach file [glob -nocomplain $latexDir/*.svg] { |
| 350 | if {$verboseMode == "YES"} { |
| 351 | puts "Info: Converting file $file..." |
| 352 | } |
| 353 | set pdffile "[file rootname $file].pdf" |
| 354 | if { [catch {exec inkscape -z -D --file=$file --export-pdf=$pdffile} res] } { |
| 355 | #puts "Error: $res." |
| 356 | return |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | # ============================================== |
| 362 | # Reference Manual-specific functions |
| 363 | # ============================================== |
| 364 | |
| 365 | # Finds dependencies between all modules |
| 366 | proc OCCDoc_CreateModulesDependencyGraph {dir filename modules mpageprefix} { |
| 367 | global module_dependency |
| 368 | |
| 369 | if {![catch {open $dir/$filename.dot "w"} file]} { |
| 370 | puts $file "digraph $filename" |
| 371 | puts $file "\{" |
| 372 | |
| 373 | foreach mod $modules { |
| 374 | if { $mod == "" } { |
| 375 | continue |
| 376 | } |
| 377 | puts $file "\t$mod \[ URL = \"[string tolower $mpageprefix$mod.html]\" \]" |
| 378 | foreach mod_depend $module_dependency($mod) { |
| 379 | puts $file "\t$mod_depend -> $mod \[ dir = \"back\", color = \"midnightblue\", style = \"solid\" \]" |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | puts $file "\}" |
| 384 | close $file |
| 385 | |
| 386 | return $filename |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | # Finds dependencies between all toolkits in module |
| 391 | proc OCCDoc_CreateModuleToolkitsDependencyGraph {dir filename modulename tpageprefix} { |
| 392 | global toolkits_in_module |
| 393 | global toolkit_dependency |
| 394 | global toolkit_parent_module |
| 395 | |
| 396 | if {![catch {open $dir/$filename.dot "w"} file]} { |
| 397 | puts $file "digraph $filename" |
| 398 | puts $file "\{" |
| 399 | |
| 400 | foreach tk $toolkits_in_module($modulename) { |
| 401 | puts $file "\t$tk \[ URL = \"[string tolower $tpageprefix$tk.html]\"\ ]" |
| 402 | foreach tkd $toolkit_dependency($tk) { |
| 403 | if { [info exists toolkit_parent_module($tkd)] } { |
| 404 | if {$toolkit_parent_module($tkd) == $modulename} { |
| 405 | puts $file "\t$tkd -> $tk \[ dir = \"back\", color = \"midnightblue\", style = \"solid\" \]" |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | puts $file "\}" |
| 412 | close $file |
| 413 | |
| 414 | return $filename |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | # Finds dependencies between the current toolkit and other toolkits |
| 419 | proc OCCDoc_CreateToolkitDependencyGraph {dir filename toolkitname tpageprefix} { |
| 420 | global toolkit_dependency |
| 421 | |
| 422 | if {![catch {open $dir/$filename.dot "w"} file]} { |
| 423 | puts $file "digraph $filename" |
| 424 | puts $file "\{" |
| 425 | |
| 426 | puts $file "\t$toolkitname \[ URL = \"[string tolower $tpageprefix$toolkitname.html]\"\, shape = box ]" |
| 427 | foreach tkd $toolkit_dependency($toolkitname) { |
| 428 | puts $file "\t$tkd \[ URL = \"[string tolower $tpageprefix$tkd.html]\"\ , shape = box ]" |
| 429 | puts $file "\t$toolkitname -> $tkd \[ color = \"midnightblue\", style = \"solid\" \]" |
| 430 | } |
| 431 | |
| 432 | if {[llength $toolkit_dependency($toolkitname)] > 1} { |
| 433 | puts $file "\taspect = 1" |
| 434 | } |
| 435 | |
| 436 | puts $file "\}" |
| 437 | close $file |
| 438 | |
| 439 | return $filename |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | # Fills arrays of modules, toolkits, dependency of modules/toolkits etc |
| 444 | proc OCCDoc_LoadData { {theProductsDir ""} } { |
| 445 | global toolkits_in_module |
| 446 | global toolkit_dependency |
| 447 | global toolkit_parent_module |
| 448 | global module_dependency |
| 449 | |
| 450 | if { $theProductsDir == ""} { |
| 451 | set modules_files [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $theProductsDir]/OS/" *.tcl] |
| 452 | } else { |
| 453 | set modules_files [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $theProductsDir]/VAS/" *.tcl] |
| 454 | } |
| 455 | |
| 456 | foreach module_file $modules_files { |
| 457 | source $module_file |
| 458 | } |
| 459 | |
| 460 | set modules [OCCDoc_GetModulesList $theProductsDir] |
| 461 | foreach mod $modules { |
| 462 | |
| 463 | if { $mod == "" } { |
| 464 | continue |
| 465 | } |
| 466 | # Get toolkits of current module |
| 467 | set toolkits_in_module($mod) [$mod:toolkits] |
| 468 | # Get all dependence of current toolkit |
| 469 | foreach tk $toolkits_in_module($mod) { |
| 470 | # set parent module of current toolkit |
| 471 | set toolkit_parent_module($tk) $mod |
| 472 | set exlibfile [open "[OCCDoc_GetSourceDir $theProductsDir]/$tk/EXTERNLIB" r] |
| 473 | set exlibfile_data [read $exlibfile] |
| 474 | set exlibfile_data [split $exlibfile_data "\n"] |
| 475 | |
| 476 | set toolkit_dependency($tk) {} |
| 477 | foreach dtk $exlibfile_data { |
| 478 | if { ([string first "TK" $dtk 0] == 0) || |
| 479 | ([string first "P" $dtk 0] == 0) } { |
| 480 | lappend toolkit_dependency($tk) $dtk |
| 481 | } |
| 482 | } |
| 483 | close $exlibfile |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | # Get modules dependency |
| 488 | foreach mod $modules { |
| 489 | set module_dependency($mod) {} |
| 490 | foreach tk $toolkits_in_module($mod) { |
| 491 | foreach tkd $toolkit_dependency($tk) { |
| 492 | if { [info exists toolkit_parent_module($tkd)] } { |
| 493 | if { $toolkit_parent_module($tkd) != $mod && |
| 494 | [lsearch $module_dependency($mod) $toolkit_parent_module($tkd)] == -1} { |
| 495 | lappend module_dependency($mod) $toolkit_parent_module($tkd) |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | # Returns list of packages of the given toolkit |
| 504 | proc OCCDoc_GetPackagesList { theToolKitPath } { |
| 505 | |
| 506 | set packages_list {} |
| 507 | |
| 508 | # Open file with list of packages of the given toolkit |
| 509 | set fileid [open "$theToolKitPath/PACKAGES" "r"] |
| 510 | |
| 511 | while { [eof $fileid] == 0 } { |
| 512 | set str [gets $fileid] |
| 513 | if { $str != "" } { |
| 514 | lappend packages_list $str |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | close $fileid |
| 519 | |
| 520 | return $packages_list |
| 521 | } |
| 522 | |
| 523 | # Returns list of modules from UDLIST |
| 524 | proc OCCDoc_GetModulesList { {theProductsDir ""} } { |
| 525 | |
| 526 | if { $theProductsDir == "" } { |
| 527 | source "[OCCDoc_GetSourceDir $theProductsDir]/OS/Modules.tcl" |
| 528 | # load a command from this file |
| 529 | set modules [OS:Modules] |
| 530 | } else { |
| 531 | source "[OCCDoc_GetSourceDir $theProductsDir]/VAS/Products.tcl" |
| 532 | # load a command from this file |
| 533 | set modules [VAS:Products] |
| 534 | } |
| 535 | |
| 536 | return $modules |
| 537 | } |
| 538 | |
| 539 | # Returns list of desired files in the specified location |
| 540 | proc OCCDoc_GetHeadersList { theDesiredContent thePackageName {theProductsDir ""} } { |
| 541 | |
| 542 | # Get list of header files with path |
| 543 | set files_list [split [glob -nocomplain -type f -directory "[OCCDoc_GetIncDir $theProductsDir]" "${thePackageName}.hxx" "${thePackageName}_*.hxx"]] |
| 544 | |
| 545 | # Get content according to desired type ('p' for path and 'f' for filenames only) |
| 546 | if { $theDesiredContent == "p" } { |
| 547 | return $files_list |
| 548 | } elseif { $theDesiredContent == "f" } { |
| 549 | |
| 550 | # Cut paths from filenames |
| 551 | foreach file $files_list { |
| 552 | set elem_index [lsearch $files_list $file] |
| 553 | lset files_list $elem_index [OCCDoc_GetNameFromPath [lindex $files_list $elem_index]] |
| 554 | } |
| 555 | return $files_list |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | # Returns location of the toolkit |
| 560 | proc OCCDoc_Locate { theToolKitName {theProductsDir ""} } { |
| 561 | set tk_dir "[OCCDoc_GetSourceDir $theProductsDir]/[OCCDoc_GetNameFromPath $theToolKitName]" |
| 562 | return $tk_dir |
| 563 | } |
| 564 | |
| 565 | # Gets contents of the given html node (for Post-processing) |
| 566 | proc OCCDoc_GetNodeContents {node props html} { |
| 567 | set openTag "<$node$props>" |
| 568 | set closingTag "</$node>" |
| 569 | set start [string first $openTag $html] |
| 570 | if {$start == -1} { |
| 571 | return "" |
| 572 | } |
| 573 | set start [expr $start + [string length $openTag]] |
| 574 | set end [string length $html] |
| 575 | set html [string range $html $start $end] |
| 576 | set start [string first $closingTag $html] |
| 577 | set end [string length $html] |
| 578 | if {$start == -1} { |
| 579 | return "" |
| 580 | } |
| 581 | set start [expr $start - 1] |
| 582 | return [string range $html 0 $start] |
| 583 | } |
| 584 | |
| 585 | # Generates main page file describing module structure |
| 586 | proc OCCDoc_MakeMainPage {outDir outFile modules {theProductsDir ""} } { |
| 587 | global env |
| 588 | |
| 589 | set one_module [expr [llength $modules] == 1] |
| 590 | set fd [open $outFile "w"] |
| 591 | |
| 592 | set module_prefix "module_" |
| 593 | set toolkit_prefix "toolkit_" |
| 594 | set package_prefix "package_" |
| 595 | |
| 596 | if { ! [file exists "$outDir/html"] } { |
| 597 | file mkdir "$outDir/html" |
| 598 | } |
| 599 | |
| 600 | OCCDoc_LoadData $theProductsDir |
| 601 | |
| 602 | # Main page: list of modules |
| 603 | if { ! $one_module } { |
| 604 | puts $fd "/**" |
| 605 | puts $fd "\\mainpage Open CASCADE Technology" |
| 606 | |
| 607 | foreach mod $modules { |
| 608 | puts $fd "\\li \\subpage [string tolower $module_prefix$mod]" |
| 609 | } |
| 610 | # insert modules relationship diagramm |
| 611 | puts $fd "\\dotfile [OCCDoc_CreateModulesDependencyGraph $outDir/html schema_all_modules $modules $module_prefix]" |
| 612 | puts $fd "**/\n" |
| 613 | } |
| 614 | |
| 615 | # One page per module: list of toolkits |
| 616 | set toolkits {} |
| 617 | foreach mod $modules { |
| 618 | if { $mod == "" } { |
| 619 | continue |
| 620 | } |
| 621 | puts $fd "/**" |
| 622 | if { $one_module } { |
| 623 | puts $fd "\\mainpage OCCT Module [$mod:name]" |
| 624 | } else { |
| 625 | puts $fd "\\page [string tolower module_$mod] Module [$mod:name]" |
| 626 | } |
| 627 | foreach tk [lsort [$mod:toolkits]] { |
| 628 | lappend toolkits $tk |
| 629 | puts $fd "\\li \\subpage [string tolower $toolkit_prefix$tk]" |
| 630 | } |
| 631 | puts $fd "\\dotfile [OCCDoc_CreateModuleToolkitsDependencyGraph $outDir/html schema_$mod $mod $toolkit_prefix]" |
| 632 | puts $fd "**/\n" |
| 633 | } |
| 634 | |
| 635 | # One page per toolkit: list of packages |
| 636 | set packages {} |
| 637 | foreach tk $toolkits { |
| 638 | puts $fd "/**" |
| 639 | puts $fd "\\page [string tolower toolkit_$tk] Toolkit $tk" |
| 640 | foreach pk [lsort [OCCDoc_GetPackagesList [OCCDoc_Locate $tk $theProductsDir]]] { |
| 641 | lappend packages $pk |
| 642 | set u [OCCDoc_GetNameFromPath $pk] |
| 643 | puts $fd "\\li \\subpage [string tolower $package_prefix$u]" |
| 644 | } |
| 645 | puts $fd "\\dotfile [OCCDoc_CreateToolkitDependencyGraph $outDir/html schema_$tk $tk $toolkit_prefix]" |
| 646 | puts $fd "**/\n" |
| 647 | } |
| 648 | |
| 649 | # One page per package: list of classes |
| 650 | foreach pk $packages { |
| 651 | set u [OCCDoc_GetNameFromPath $pk] |
| 652 | puts $fd "/**" |
| 653 | puts $fd "\\page [string tolower $package_prefix$u] Package $u" |
| 654 | foreach hdr [lsort [OCCDoc_GetHeadersList "f" "$pk" "$theProductsDir"]] { |
| 655 | if { ! [regexp {^Handle_} $hdr] && [regexp {(.*)[.]hxx} $hdr str obj] } { |
| 656 | puts $fd "\\li \\subpage $obj" |
| 657 | } |
| 658 | } |
| 659 | puts $fd "**/\n" |
| 660 | } |
| 661 | |
| 662 | close $fd |
| 663 | |
| 664 | return $outFile |
| 665 | } |
| 666 | |
| 667 | # Parses generated files to add a navigation path |
| 668 | proc OCCDoc_PostProcessor {outDir} { |
| 669 | puts "[clock format [clock seconds] -format {%Y.%m.%d %H:%M}] Post-process is started ..." |
| 670 | append outDir "/html" |
| 671 | set files [glob -nocomplain -type f $outDir/package_*] |
| 672 | if { $files != {} } { |
| 673 | foreach f [lsort $files] { |
| 674 | set packageFilePnt [open $f r] |
| 675 | set packageFile [read $packageFilePnt] |
| 676 | set navPath [OCCDoc_GetNodeContents "div" " id=\"nav-path\" class=\"navpath\"" $packageFile] |
| 677 | set packageName [OCCDoc_GetNodeContents "div" " class=\"title\"" $packageFile] |
| 678 | regsub -all {<[^<>]*>} $packageName "" packageName |
| 679 | |
| 680 | # add package link to nav path |
| 681 | set first [expr 1 + [string last "/" $f]] |
| 682 | set last [expr [string length $f] - 1] |
| 683 | set packageFileName [string range $f $first $last] |
| 684 | set end [string first "</ul>" $navPath] |
| 685 | set end [expr $end - 1] |
| 686 | set navPath [string range $navPath 0 $end] |
| 687 | append navPath " <li class=\"navelem\"><a class=\"el\" href=\"$packageFileName\">$packageName</a> </li>\n </ul>" |
| 688 | |
| 689 | # get list of files to update |
| 690 | set listContents [OCCDoc_GetNodeContents "div" " class=\"textblock\"" $packageFile] |
| 691 | set listContents [OCCDoc_GetNodeContents "ul" "" $listContents] |
| 692 | set lines [split $listContents "\n"] |
| 693 | foreach line $lines { |
| 694 | if {[regexp {href=\"([^\"]*)\"} $line tmpLine classFileName]} { |
| 695 | # check if anchor is there |
| 696 | set anchorPos [string first "#" $classFileName] |
| 697 | if {$anchorPos != -1} { |
| 698 | set classFileName [string range $classFileName 0 [expr $anchorPos - 1]] |
| 699 | } |
| 700 | |
| 701 | # read class file |
| 702 | set classFilePnt [open $outDir/$classFileName r+] |
| 703 | set classFile [read $classFilePnt] |
| 704 | |
| 705 | # find position of content block |
| 706 | set contentPos [string first "<div class=\"header\">" $classFile] |
| 707 | set navPart [string range $classFile 0 [expr $contentPos - 1]] |
| 708 | |
| 709 | # position where to insert nav path |
| 710 | set posToInsert [string last "</div>" $navPart] |
| 711 | set prePart [string range $classFile 0 [expr $posToInsert - 1]] |
| 712 | set postPart [string range $classFile $posToInsert [string length $classFile]] |
| 713 | set newClassFile "" |
| 714 | append newClassFile $prePart " <div id=\"nav-path\" class=\"navpath\">" $navPath \n " </div>" \n $postPart |
| 715 | |
| 716 | # write updated content |
| 717 | seek $classFilePnt 0 |
| 718 | puts $classFilePnt $newClassFile |
| 719 | close $classFilePnt |
| 720 | } |
| 721 | } |
| 722 | close $packageFilePnt |
| 723 | } |
| 724 | return 0 |
| 725 | } else { |
| 726 | puts "no files found" |
| 727 | return 1 |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | # ====================================== |
| 732 | # User Guides-specific functions |
| 733 | # ====================================== |
| 734 | |
| 735 | # Loads a list of docfiles from file FILES.txt |
| 736 | proc OCCDoc_LoadFilesList {} { |
| 737 | |
| 738 | set INPUTDIR [OCCDoc_GetDoxDir] |
| 739 | |
| 740 | global available_docfiles |
| 741 | set available_docfiles {} |
| 742 | |
| 743 | # Read data from file |
| 744 | if { [file exists "$INPUTDIR/FILES_HTML.txt"] == 1 } { |
| 745 | set FILE [open "$INPUTDIR/FILES_HTML.txt" r] |
| 746 | while {1} { |
| 747 | set line [string trim [gets $FILE]] |
| 748 | |
| 749 | # trim possible comments starting with '#' |
| 750 | set line [regsub {\#.*} $line {}] |
| 751 | if {$line != ""} { |
| 752 | lappend available_docfiles $line |
| 753 | } |
| 754 | if {[eof $FILE]} { |
| 755 | close $FILE |
| 756 | break |
| 757 | } |
| 758 | } |
| 759 | } else { |
| 760 | return -1 |
| 761 | } |
| 762 | |
| 763 | global available_pdf |
| 764 | set available_pdf {} |
| 765 | |
| 766 | # Read data from file |
| 767 | if { [file exists "$INPUTDIR/FILES_PDF.txt"] } { |
| 768 | set FILE [open "$INPUTDIR/FILES_PDF.txt" r] |
| 769 | while {1} { |
| 770 | set line [string trim [gets $FILE]] |
| 771 | |
| 772 | # Trim possible comments starting with '#' |
| 773 | set line [regsub {\#.*} $line {}] |
| 774 | if {$line != ""} { |
| 775 | lappend available_pdf $line |
| 776 | } |
| 777 | if {[eof $FILE]} { |
| 778 | close $FILE |
| 779 | break |
| 780 | } |
| 781 | } |
| 782 | } else { |
| 783 | return -1 |
| 784 | } |
| 785 | return 0 |
| 786 | } |
| 787 | |
| 788 | # Writes new TeX file for conversion from tex to pdf for a specific doc |
| 789 | proc OCCDoc_MakeRefmanTex {fileName latexDir verboseMode latexFilesList} { |
| 790 | |
| 791 | if { $verboseMode == "YES" } { |
| 792 | puts "Info: Making refman.tex file for $fileName..." |
| 793 | } |
| 794 | set DOCNAME "$latexDir/refman.tex" |
| 795 | if {[file exists $DOCNAME] == 1} { |
| 796 | file delete -force $DOCNAME |
| 797 | } |
| 798 | |
| 799 | # Copy template file to latex folder |
| 800 | file copy "[OCCDoc_GetDoxDir]/resources/occt_pdf_template.tex" $DOCNAME |
| 801 | |
| 802 | # Get templatized data |
| 803 | set texfile [open $DOCNAME "r"] |
| 804 | set texfile_loaded [read $texfile] |
| 805 | close $texfile |
| 806 | |
| 807 | # Replace dummy values |
| 808 | set year [clock format [clock seconds] -format {%Y}] |
| 809 | set texfile [open $DOCNAME "w"] |
| 810 | set casVersion [OCCDoc_DetectCasVersion] |
| 811 | |
| 812 | # Get name of the document |
| 813 | set docLabel "" |
| 814 | foreach aFileName $latexFilesList { |
| 815 | # Find the file in FILES_PDF.txt |
| 816 | set parsedFileName [split $aFileName "/" ] |
| 817 | set newfileName [string range $fileName [expr [string first "__" $fileName] + 2] end] |
| 818 | |
| 819 | if { [lsearch -nocase $parsedFileName "$newfileName.md" ] != -1 } { |
| 820 | set filepath "[OCCDoc_GetDoxDir]/$aFileName" |
| 821 | if { [file exists $filepath] } { |
| 822 | set MDFile [open $filepath "r"] |
| 823 | set label [split [gets $MDFile] "\{"] |
| 824 | set docLabel [lindex $label 0] |
| 825 | close $MDFile |
| 826 | |
| 827 | break |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | set texfile_loaded [string map [list DEFDOCLABEL "$docLabel" DEFCASVERSION "$casVersion" DEFFILENAME "$fileName" DEFYEAR "$year"] $texfile_loaded] |
| 833 | |
| 834 | # Get data |
| 835 | puts $texfile $texfile_loaded |
| 836 | |
| 837 | close $texfile |
| 838 | } |
| 839 | |
| 840 | # Postprocesses generated TeX files |
| 841 | proc OCCDoc_ProcessTex {{texFiles {}} {latexDir} verboseMode} { |
| 842 | |
| 843 | foreach TEX $texFiles { |
| 844 | if {$verboseMode == "YES"} { |
| 845 | puts "Info: Preprocessing file $TEX..." |
| 846 | } |
| 847 | |
| 848 | if {![file exists $TEX]} { |
| 849 | puts "Error: file $TEX does not exist." |
| 850 | return -1 |
| 851 | } |
| 852 | |
| 853 | set IN_F [open "$TEX" "r"] |
| 854 | set TMPFILENAME "$latexDir/temp.tex" |
| 855 | set OUT_F [open $TMPFILENAME w] |
| 856 | |
| 857 | while {1} { |
| 858 | set line [gets $IN_F] |
| 859 | if { [string first "\\includegraphics" $line] != -1 } { |
| 860 | # replace svg extension by pdf |
| 861 | set line [regsub {[.]svg} $line ".pdf"] |
| 862 | # Center images in TeX files |
| 863 | set line "\\begin{center}\n $line\n\\end{center}" |
| 864 | } elseif { [string first "\\subsection" $line] != -1 } { |
| 865 | # Replace \subsection with \section tag |
| 866 | regsub -all "\\\\subsection" $line "\\\\section" line |
| 867 | } elseif { [string first "\\subsubsection" $line] != -1 } { |
| 868 | # Replace \subsubsection with \subsection tag |
| 869 | regsub -all "\\\\subsubsection" $line "\\\\subsection" line |
| 870 | } elseif { [string first "\\paragraph" $line] != -1 } { |
| 871 | # Replace \paragraph with \subsubsection tag |
| 872 | regsub -all "\\\\paragraph" $line "\\\\subsubsection" line |
| 873 | } |
| 874 | puts $OUT_F $line |
| 875 | |
| 876 | if {[eof $IN_F]} { |
| 877 | close $IN_F |
| 878 | close $OUT_F |
| 879 | break |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | file delete -force $TEX |
| 884 | file rename $TMPFILENAME $TEX |
| 885 | } |
| 886 | } |