getSimLayout.tcl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package require tdom
  2. proc getSimLayout { curframe {dirname ./} {xmlFile Sim.SimInfo} {txtFile graph.txt} {pngFile graph.gif} } {
  3. #set xmlFile ./Sim.SimInfo
  4. #set txtFile ./graph.txt
  5. #set pngFile ./graph.png
  6. set size [file size $dirname$xmlFile]
  7. set fd [open $dirname$xmlFile]
  8. set xml [read $fd $size]
  9. close $fd
  10. set doc [dom parse -simple $xml]
  11. set root [$doc documentElement]
  12. set fh [open $dirname$txtFile "w"]
  13. puts $fh "digraph finite_state_machine {"
  14. puts $fh "size=\"7,7\";"
  15. puts connection
  16. foreach connection [$root selectNodes Connection] {
  17. # remove the next two lines
  18. puts aa
  19. puts $connection
  20. set DotCommand ""
  21. set SourceId [[$connection child 1 Source] getAttribute id]
  22. set SourceName [[$root find id $SourceId] getAttribute Name]
  23. set TargetId [[$connection child 1 Target] getAttribute id]
  24. set TargetName [[$root find id $TargetId] getAttribute Name]
  25. append DotCommand "\"" $SourceName "\" -> \"" $TargetName "\""
  26. set InputNr [[$connection child 1 InputNumber] getAttribute value]
  27. switch $InputNr {
  28. 0 {}
  29. 1 {append DotCommand " \[arrowhead = tee\]"}
  30. 2 {}
  31. 3 {append DotCommand " \[arrowhead = tee\]"}
  32. }
  33. puts "Dot= $DotCommand"
  34. append DotCommand " ;"
  35. puts $fh $DotCommand
  36. }
  37. puts $fh "}"
  38. close $fh
  39. exec dot -Tgif $dirname$txtFile -o $dirname$pngFile
  40. $doc delete
  41. LayoutImage read $dirname$pngFile -shrink
  42. set imageWidth [image width LayoutImage]
  43. set imageHeight [image height LayoutImage]
  44. ${curframe}.layoutCanvas configure -width $imageWidth -height $imageHeight
  45. }
  46. proc ShowLayoutWindow {LayoutWindowName SimDataDir {pngFile graph.gif} } {
  47. set ::VisibleSimLayout 1
  48. toplevel $LayoutWindowName
  49. wm protocol $LayoutWindowName WM_DELETE_WINDOW "HideWin $LayoutWindowName ::VisibleSimLayout"
  50. set curframe ${::LayoutWindowName}
  51. puts "getSimLayout $SimDataDir"
  52. pack [button ${curframe}.actualize -command "getSimLayout $curframe $SimDataDir" -text "actualize Picture"]
  53. image create photo LayoutImage
  54. if {[file exists $SimDataDir$pngFile] == 1} {
  55. LayoutImage read $SimDataDir$pngFile
  56. set imageWidth [image width LayoutImage]
  57. set imageHeight [image height LayoutImage]
  58. } else {
  59. set imageWidth 100
  60. set imageHeight 20
  61. }
  62. pack [canvas ${curframe}.layoutCanvas -height $imageHeight -width $imageWidth]
  63. ${curframe}.layoutCanvas create image 0 0 -image LayoutImage -anchor nw
  64. }
  65. proc doSomething {} {
  66. puts dlskjfsdlk
  67. }