Changeset 6071


Ignore:
Timestamp:
Feb 28, 2016, 2:40:31 AM (9 years ago)
Author:
ldelgass
Message:

Add method to get file properties from CSS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/map.tcl

    r6061 r6071  
    6161    public method viewpoints {}
    6262
    63     protected method Parse { xmlobj path }
     63    public proc getFilesFromStylesheet { stylesheet }
     64
     65    protected method parseXML { xmlobj path }
     66
     67    protected proc isFileProp { prop }
     68    protected proc parseStylesheet { stylesheet }
    6469
    6570    private variable _tree "";         # Tree of information about the map.
     
    105110            error "bad value \"$xmlobj\": should be LibraryObj"
    106111        }
    107         Parse $xmlobj $path
     112        parseXML $xmlobj $path
    108113    }
    109114}
     
    134139
    135140#
    136 # Parse --
     141# parseXML --
    137142#
    138143#   Parses the map description in the XML object.
    139144#
    140 itcl::body Rappture::Map::Parse { xmlobj path } {
     145itcl::body Rappture::Map::parseXML { xmlobj path } {
    141146
    142147    set map [$xmlobj element -as object $path]
     
    884889    return [expr {[hints "type"] eq "geocentric"}]
    885890}
     891
     892itcl::body Rappture::Map::isFileProp { prop } {
     893    foreach fileprop {
     894        icon
     895        model
     896    } {
     897        if { $prop eq $fileprop } {
     898            return 1
     899        }
     900    }
     901    return 0
     902}
     903
     904tcl::body Rappture::Map::parseStylesheet { stylesheet } {
     905    set styles [list]
     906    # First split into style blocks
     907    set blocks [split $stylesheet "\{\}"]
     908    if {[llength $blocks] == 1} {
     909        set blocks [list style $blocks]
     910    }
     911    foreach {styleName block} $blocks {
     912        # Get name/value pairs
     913        set styleName [string trim $styleName]
     914        if {$styleName == ""} { set styleName "style" }
     915        set block [string trim $block " \t\n\r\{\}"]
     916        if {$block == ""} { continue }
     917        #puts stderr "styleName: \"$styleName\""
     918        #puts stderr "block: \"$block\""
     919        set lines [split $block ";"]
     920        foreach line $lines {
     921            set line [string trim $line]
     922            if {$line == "" || [string index $line 0] == "#"} { continue }
     923            #puts stderr "line: \"$line\""
     924            set delim [string first ":" $line]
     925            set prop [string trim [string range $line 0 [expr {$delim-1}]]]
     926            set val [string trim [string range $line [expr {$delim+1}] end]]
     927            set ${styleName}($prop) $val
     928        }
     929        lappend styles $styleName [array get $styleName]
     930    }
     931    return $styles
     932}
     933
     934itcl::body Rappture::Map::getFilesFromStylesheet { stylesheet } {
     935    set files [list]
     936    set styles [parseStylesheet $stylesheet]
     937    foreach {name style} $styles {
     938        #puts stderr "Style: \"$name\""
     939        array unset info
     940        array set info $style
     941        foreach key [array names info] {
     942            #puts stderr "Prop: \"$key\" Val: \"$info($key)\""
     943            if {[isFileProp $key]} {
     944                lappend files $info($key)
     945            }
     946        }
     947    }
     948    return $files
     949}
Note: See TracChangeset for help on using the changeset viewer.