obj method canvaseditor processXML src { set tree [xml parse $src] foreach {att val} [dict get $tree attribute] { if {$att ne "id"} then { $self setting $att $val switch -exact -- $att { width - height - background - bg { $self canvas configure -$att $val } } } } if {[dict get $tree name] eq "canvaseditor"} then { $self canvas configure -scrollregion\ "0 0 [$self canvas cget -width] [$self canvas cget -height]" } set id2obj {} # dot foreach path [::xml findElementsByName $tree dot] { set dotTree [::xml getElement $tree {*}$path] set dotID [dict get $dotTree attribute id] if {![dict exists $id2obj $dotID]} then { set code "obj new dot\ -x [dict get $dotTree attribute x]\ -y [dict get $dotTree attribute y]" dict set id2obj $dotID [eval $code] } } # line foreach path [::xml findElementsByName $tree line] { set lineTree [::xml getElement $tree {*}$path] set lineID [dict get $lineTree attribute id] if {![dict exists $id2obj $lineID]} then { set code "obj new line" foreach {key val} [dict get $lineTree attribute] { if {$key ni {id}} then { lappend code -$key $val } } foreach dotTree [dict get $lineTree content] { set dotID [dict get $dotTree attribute id] lappend code [dict get $id2obj $dotID] } dict set id2obj $lineID [eval $code] } } # fill foreach path [::xml findElementsByName $tree fill] { set fillTree [::xml getElement $tree {*}$path] set fillID [dict get $fillTree attribute id] set code "obj new fill" lappend code\ -fill [dict get $fillTree attribute fill]\ -constraint [dict get $fillTree attribute constraint] foreach lineTree [dict get $fillTree content] { set lineID [dict get $lineTree attribute id] lappend code [dict get $id2obj $lineID] } if {![dict exists $id2obj $fillID]} then { dict set id2obj $fillID [eval $code] } } # group foreach path [lreverse [::xml findElementsByName $tree group]] { set groupTree [::xml getElement $tree {*}$path] set groupID [dict get $groupTree attribute id] set code "obj new group" if {[dict exists $groupTree attribute constraint]} then { lappend code -constraint [dict get $groupTree attribute constraint] } foreach elTree [dict get $groupTree content] { set elID [dict get $elTree attribute id] lappend code [dict get $id2obj $elID] } if {![dict exists $id2obj $groupID]} then { dict set id2obj $groupID [eval $code] } } set lines {} # elements foreach path [::xml findElementsByName $tree elements] { set elementTree [::xml getElement $tree {*}$path] foreach objTree [dict get $elementTree content] { set id [dict get $objTree attribute id] lappend lines "[dict get $id2obj $id] draw" } } set line "$self raiseTags" # stack foreach path [::xml findElementsByName $tree stack] { set elementTree [::xml getElement $tree {*}$path] foreach objTree [dict get $elementTree content] { set id [dict get $objTree attribute ref] set obj [dict get $id2obj $id] set tag [$obj info class]$obj lappend line $tag } } lappend lines $line eval [join $lines \n] }
© Wolf-Dieter Busch | Home | Sitemap | Urheber | A-Z