getSimLayout 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/tclsh
  2. package require tdom
  3. set xmlFile ./Sim.SimInfo
  4. set txtFile ./graph.txt
  5. set pngFile ./graph.png
  6. set size [file size $xmlFile]
  7. set fd [open $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 $txtFile "w"]
  13. puts $fh "digraph finite_state_machine {"
  14. puts $fh "size=\"7,7\";"
  15. foreach connection [$root selectNodes Connection] {
  16. set command ""
  17. set SourceId [[$connection child 1 Source] getAttribute id]
  18. set SourceName [[$root find id $SourceId] getAttribute Name]
  19. set TargetId [[$connection child 1 Target] getAttribute id]
  20. set TargetName [[$root find id $TargetId] getAttribute Name]
  21. append command $SourceName " -> " $TargetName
  22. set InputNr [[$connection child 1 InputNumber] getAttribute value]
  23. switch $InputNr {
  24. 0 {}
  25. 1 {append command " \[arrowhead = tee\]"}
  26. 2 {}
  27. 3 {append command " \[arrowhead = tee\]"}
  28. }
  29. append command " ;"
  30. puts $fh $command
  31. }
  32. puts $fh "}"
  33. close $fh
  34. exec dot -Tpng $txtFile -o $pngFile
  35. $doc delete