Changeset 3102


Ignore:
Timestamp:
Jul 17, 2012 7:02:05 AM (12 years ago)
Author:
gah
Message:

Fixes for drawing. Allow empty html file.

Location:
branches/blt4
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/examples/zoo/drawing/tool.xml

    r2966 r3102  
    8787          <dash>4 2</dash>
    8888        </grid>
    89         <string>
    90           <about>
    91             <label>String:</label>
    92           </about> 
    93           <coords>.1 1.1</coords>
    94           <color>blue</color>
    95           <font>Arial 9</font>
    96           <anchor>nw</anchor>
    97           <default>value</default>
    98         </string>
    99         <number>
    100           <about>
    101             <label>Number:</label>
    102           </about> 
    103           <coords></coords>
    104           <color>blue</color>
    105           <font>Arial 12</font>
    106           <anchor>n</anchor>
    107           <default></default>
    108           <min></min>
    109           <max></max>
    110         </number>
    11189    </components>
    11290  </drawing>
  • branches/blt4/gui/scripts/Makefile.in

    r3029 r3102  
    3030                $(srcdir)/color.tcl \
    3131                $(srcdir)/combobox.tcl \
     32                $(srcdir)/combochecks.tcl \
    3233                $(srcdir)/contourresult.tcl \
    3334                $(srcdir)/controlOwner.tcl \
     
    4344                $(srcdir)/dispatcher.tcl \
    4445                $(srcdir)/drawing.tcl \
    45                 $(srcdir)/drawingentry.tcl \
    4646                $(srcdir)/drawingcontrols.tcl \
    4747                $(srcdir)/drawingentry.tcl \
    4848                $(srcdir)/dropdown.tcl \
     49                $(srcdir)/dropdownchecks.tcl \
    4950                $(srcdir)/dropdownlist.tcl \
    5051                $(srcdir)/editor.tcl \
  • branches/blt4/gui/scripts/controls.tcl

    r3025 r3102  
    522522            set _name2info($name-label) $label
    523523
    524             $_tabs insert end $label -fill both
     524            $_tabs insert end $name -text $label -fill both
    525525            incr gn
    526526        }
  • branches/blt4/gui/scripts/drawingentry.tcl

    r3000 r3102  
    2727    private variable _drawingWidth 0
    2828    private variable _owner
    29     private variable _parser ""
     29    private variable _parser "";        # Slave interpreter where all
     30                                        # substituted variables are stored.
    3031    private variable _path
    3132    private variable _showing ""
     
    4041    private variable _cursor ""
    4142
    42     constructor {owner path args} { # defined below }
    43 
     43    constructor {owner path args} {
     44        # defined below
     45    }
     46    destructor {
     47        # defined below
     48    }
    4449    public method value { args }
    4550    public method label {}
     
    4853    private method Activate { tag }
    4954    private method AdjustDrawingArea { xAspect yAspect }
     55    private method ControlValue {path {units ""}}
    5056    private method Deactivate { tag }
    5157    private method Highlight { tag }
     
    6975    private method ScreenY { y }
    7076    private method XmlGet { path }
    71     private method Withdraw {}
     77    private method XmlGetSubst { path }
     78    private method Withdraw { cname }
     79    private method Hotspot { option cname item args }
     80    private method IsEnabled { path }
     81    private method NumControlsEnabled { cname }
    7282}
    7383
     
    99109    pack $itk_component(drawing) -expand yes -fill both
    100110    bind $itk_component(drawing) <Configure> [itcl::code $this Redraw]
     111    set _parser [interp create -safe]
    101112    Redraw
    102113    eval itk_initialize $args
    103114}
    104115
     116itcl::body Rappture::DrawingEntry::destructor {} {
     117    if { $_parser != "" } {
     118        $_parser delete
     119    }
     120}
    105121# ----------------------------------------------------------------------
    106122# USAGE: label
     
    226242    }
    227243    # Coords
    228     set xcoords [XmlGet $cpath.xcoords]
     244    set xcoords [XmlGetSubst $cpath.xcoords]
    229245    set xcoords [string trim $xcoords]
    230     set ycoords [XmlGet $cpath.ycoords]
     246    set ycoords [XmlGetSubst $cpath.ycoords]
    231247    set ycoords [string trim $ycoords]
    232248    if { $ycoords == "" } {
     
    275291        if { [info exists attr2option($attr)] } {
    276292            set option $attr2option($attr)
    277             set value [XmlGet $cpath.$attr]
     293            set value [XmlGetSubst $cpath.$attr]
    278294            set options($option) $value
    279295        }
     
    311327        if { [info exists attr2option($attr)] } {
    312328            set option $attr2option($attr)
    313             set value [XmlGet $cpath.$attr]
     329            set value [XmlGetSubst $cpath.$attr]
    314330            set options($option) $value
    315331        } elseif { [string match "controls*" $attr] } {
    316             set value [XmlGet $cpath.$attr]
     332            set value [XmlGetSubst $cpath.$attr]
    317333            lappend _cname2controls($cname) $value
    318334            $_owner xml put $value.hide 1
     
    320336    }
    321337    # Coordinates
    322     set coords [XmlGet $cpath.coords]
     338    set coords [XmlGetSubst $cpath.coords]
    323339    set coords [ScreenCoords $coords]
    324340    if { $coords == "" } {
     
    326342    }
    327343    set c $itk_component(drawing)
    328     set img [Rappture::icon question_mark12]
     344    set img [Rappture::icon hotspot_normal]
    329345    foreach { x1 y1 } $coords break
    330346    set id [$itk_component(drawing) create image $x1 $y1]
     
    337353    $c bind $id <Leave> [itcl::code $this Deactivate $cname]
    338354    #$c bind $id <ButtonPress-1> [itcl::code $this Depress $cname]
    339     $c bind $id <ButtonRelease-1> [itcl::code $this Invoke $cname $x1 $y1]
     355    set bbox [$c bbox $id]
     356    set y1 [lindex $bbox 1]
     357    $c bind $id <ButtonPress-1> [itcl::code $this Invoke $cname $x1 $y1]
    340358}
    341359
     
    359377    # Coords
    360378    set coords {}
    361     set coords [XmlGet $cpath.coords]
     379    set coords [XmlGetSubst $cpath.coords]
    362380    set coords [string trim $coords]
    363381    if { $coords == "" } {
     
    371389        if { [info exists attr2option($attr)] } {
    372390            set option $attr2option($attr)
    373             set value [XmlGet $cpath.$attr]
     391            set value [XmlGetSubst $cpath.$attr]
    374392            set options($option) $value
    375393        }
     
    388406        "outline"       "-outline"
    389407        "fill"          "-fill"
    390         "linewidth"     "-linewidth"
     408        "linewidth"     "-width"
    391409    }
    392410    #puts stderr "ParseOval owner=$_owner cpath=$cpath"
     
    395413    array set options {
    396414        -fill blue
    397         -linewidth 1
     415        -width 1
    398416        -outline black
    399417    }
     
    401419        if { [info exists attr2option($attr)] } {
    402420            set option $attr2option($attr)
    403             set value [XmlGet $cpath.$attr]
     421            set value [XmlGetSubst $cpath.$attr]
    404422            set options($option) $value
    405423        }
     
    407425    # Coordinates
    408426    set coords {}
    409     set coords [XmlGet $cpath.coords]
     427    set coords [XmlGetSubst $cpath.coords]
    410428    set coords [string trim $coords]
    411429    if { $coords == "" } {
     
    413431    }
    414432    foreach { x1 y1 x2 y2 } [ScreenCoords $coords] break
    415     set id [eval $itk_component(drawing) create oval $coords]
     433    set id [$itk_component(drawing) create oval $x1 $y1 $x2 $y2]
    416434    set _cname2id($cname) $id
     435    eval $itk_component(drawing) itemconfigure $id [array get options]
    417436}
    418437
     
    432451        if { [info exists attr2option($attr)] } {
    433452            set option $attr2option($attr)
    434             set value [XmlGet $cpath.$attr]
     453            set value [XmlGetSubst $cpath.$attr]
    435454            set options($option) $value
    436455        }
    437456    }
    438     set contents [XmlGet $cpath.contents]
     457    set contents [XmlGetSubst $cpath.contents]
    439458    set img ""
    440459    if { [string compare -length 5 $contents "file:"] == 0 } {
     
    453472    }
    454473    # Coordinates
    455     set coords [XmlGet $cpath.coords]
     474    set coords [XmlGetSubst $cpath.coords]
    456475    set coords [ScreenCoords $coords]
    457476    if { [llength $coords] == 2 } {
    458477        foreach { x1 y1 } $coords break
    459         set w [XmlGet $cpath.width]
     478        set w [XmlGetSubst $cpath.width]
    460479        if { $w == "" || ![string is number $w] || $w <= 0.0 } {
    461480            set width [expr [image width $img] / 4]
     
    463482            set width [expr [ScreenX $w] - [ScreenX 0]]
    464483        }
    465         set h [XmlGet $cpath.height]
     484        set h [XmlGetSubst $cpath.height]
    466485        if { $h == "" || ![string is number $h] || $h <= 0.0 } {
    467486            set height [expr [image height $img] / 4]
     
    517536    array set attr2option {
    518537        "linewidth"     "-width"
    519         "arrow"         "-arrow"
    520538        "color"         "-fill"
    521539    }
    522540    # Set default options first and then let tool.xml override them.
    523541    array set options {
    524         -arrow          none
    525         -width          0
    526         -fill           black
     542        -width          1
     543        -fill           blue
     544        -outline        black
    527545    }
    528546    # Coords
    529     set coords [XmlGet $cpath.coords]
     547    set coords [XmlGetSubst $cpath.coords]
    530548    set coords [string trim $coords]
    531549    if { $coords == "" } {
     
    542560        if { [info exists attr2option($attr)] } {
    543561            set option $attr2option($attr)
    544             set value [XmlGet $cpath.$attr]
     562            set value [XmlGetSubst $cpath.$attr]
    545563            set options($option) $value
    546564        }
     
    559577        "outline"       "-outline"
    560578        "fill"          "-fill"
    561         "linewidth"     "-linewidth"
     579        "color"         "-fill"
     580        "linewidth"     "-width"
    562581    }
    563582    #puts stderr "ParseRectangle owner=$_owner cpath=$cpath"
     
    566585    array set options {
    567586        -fill blue
    568         -linewidth 1
     587        -width 1
    569588        -outline black
    570589    }
     
    572591        if { [info exists attr2option($attr)] } {
    573592            set option $attr2option($attr)
    574             set value [XmlGet $cpath.$attr]
     593            set value [XmlGetSubst $cpath.$attr]
    575594            set options($option) $value
    576595        }
    577596    }
    578597    # Coordinates
    579     set coords [XmlGet $cpath.coords]
     598    set coords [XmlGetSubst $cpath.coords]
    580599    set coords [string trim $coords]
    581600    if { $coords == "" } {
     
    583602    }
    584603    foreach { x1 y1 x2 y2 } [ScreenCoords $coords] break
    585     set id [eval $itk_component(drawing) create rectangle $coords]
     604    set id [$itk_component(drawing) create rectangle $x1 $y1 $x2 $y2]
    586605    set _cname2id($cname) $id
     606    eval $itk_component(drawing) itemconfigure $id [array get options]
    587607}
    588608
     
    593613    array set attr2option {
    594614        "font"          "-font"
    595         "color"         "-fill"
     615        "color"         "-foreground"
     616        "valuecolor"    "-valueforeground"
    596617        "text"          "-text"
    597618        "anchor"        "-anchor"
     
    601622    # Set default options first and then let tool.xml override them.
    602623    array set options {
    603         -font {Arial 8}
     624        -font {Arial 12}
     625        -valuefont {Arial 12}
     626        -valueforeground blue3
    604627        -text {}
    605         -fill black
     628        -fill {}
    606629        -anchor c
    607630    }
     
    609632        if { [info exists attr2option($attr)] } {
    610633            set option $attr2option($attr)
    611             set value [XmlGet $cpath.$attr]
     634            if { $attr == "text" } {
     635                set value [XmlGet $cpath.$attr]
     636            } else {
     637                set value [XmlGetSubst $cpath.$attr]
     638            }
    612639            set options($option) $value
    613640        }
    614641    }
    615642    # Coords
    616     set coords [XmlGet $cpath.coords]
     643    set coords [XmlGetSubst $cpath.coords]
    617644    set coords [string trim $coords]
    618645    if { $coords == "" } {
     
    621648        set coords [ScreenCoords $coords]
    622649    }
     650    set hotspot [XmlGetSubst $cpath.hotspot]
     651    if { $hotspot == "inline" } {
     652        set options(-showicons) 1
     653    }
     654    set c $itk_component(drawing)
    623655    set options(-tags) $cname
    624     set id [eval $itk_component(drawing) create text $coords]
     656    set img [Rappture::icon hotspot_normal]
     657    set options(-image) $img
     658    set img [Rappture::icon hotspot_active]
     659    set options(-activeimage) $img
     660    set id [eval $c create hotspot $coords]
    625661    set _cname2id($cname) $id
    626     eval $itk_component(drawing) itemconfigure $id [array get options]
     662    set options(-interp) $_parser
     663    eval $c itemconfigure $id [array get options]
     664    if { $hotspot == "inline" } {
     665        array unset _cname2controls $cname
     666        foreach varName [Rappture::hotspot variables $c $id] {
     667            if { [info exists _name2path($varName)] } {
     668                set path $_name2path($varName)
     669                $_owner xml put $path.hide 1
     670                lappend _cname2controls($cname) $path
     671            } else {
     672                puts stderr "unknown varName=$varName"
     673            }
     674        }
     675        $c bind $id <Motion> \
     676            [itcl::code $this Hotspot watch $cname $id %x %y]
     677        $c bind $id <Leave> \
     678            [itcl::code $this Hotspot deactivate $cname $id]
     679        $c bind $id <Enter> \
     680            [itcl::code $this Hotspot activate $cname $id %x %y]
     681        $c bind $id <ButtonRelease-1> \
     682            [itcl::code $this Hotspot invoke $cname $id %x %y]
     683    }
     684}
     685
     686
     687itcl::body Rappture::DrawingEntry::Hotspot { option cname item args } {
     688    if { [NumControlsEnabled $cname] == 0 } {
     689        return
     690    }
     691    set c $itk_component(drawing)
     692    switch -- $option {
     693        "activate" {
     694            foreach { x y } $args break
     695            set varName  [Rappture::hotspot identify $c $item $x $y]
     696            $c itemconfigure $item -activevalue $varName
     697        }
     698        "deactivate" {
     699            $c itemconfigure $item -activevalue ""
     700        }
     701        "watch" {
     702            foreach { x y } $args break
     703            set active [$c itemcget $item -activevalue]
     704            set varName  [Rappture::hotspot identify $c $item $x $y]
     705            if { $varName != $active  } {
     706                $c itemconfigure $item -activevalue $varName
     707            }
     708        }
     709        "invoke" {
     710            foreach { x y } $args break
     711            set active [$c itemcget $item -activevalue]
     712            set varName  [Rappture::hotspot identify $c $item $x $y]
     713            if { $varName != "" } {
     714                set bbox [$c bbox $item]
     715                Invoke $cname $x [lindex $bbox 1]
     716            }
     717        }
     718    }
    627719}
    628720
     
    825917    set popup .drawingentrypopup
    826918    if { ![winfo exists $popup] } {
    827         # Create a popup for the print dialog
     919        # Create a popup for the controls dialog
    828920        Rappture::Balloon $popup -title "Change values..." \
    829             -deactivatecommand [itcl::code $this Withdraw]
     921            -deactivatecommand [itcl::code $this Withdraw $cname]
    830922        set inner [$popup component inner]
    831923        Rappture::DrawingControls $inner.controls $_owner \
     
    836928        $inner.controls delete all
    837929    }
     930    set count 0
    838931    foreach path $controls {
    839         $inner.controls add $path
     932        if { [IsEnabled $path] } {
     933            $inner.controls add $path
     934            incr count
     935        }
     936    }
     937    if { $count == 0 } {
     938        return
    840939    }
    841940    update
     
    843942    incr x [winfo rootx $itk_component(drawing)]
    844943    incr y [winfo rooty $itk_component(drawing)]
    845    
    846944    $popup activate @$x,$y above
    847945}
     
    851949#
    852950itcl::body Rappture::DrawingEntry::Activate { cname } {
    853     $itk_component(drawing) configure -cursor center_ptr
     951    $itk_component(drawing) configure -cursor center_ptr
     952    $itk_component(drawing) itemconfigure $_cname2id($cname) \
     953        -image [Rappture::icon hotspot_active]
    854954}
    855955
     
    858958#
    859959itcl::body Rappture::DrawingEntry::Deactivate { cname } {
    860     $itk_component(drawing) configure -cursor left_ptr
    861 }
    862 
    863 #
    864 # Invoke --
    865 #
    866 itcl::body Rappture::DrawingEntry::Withdraw {} {
     960    $itk_component(drawing) configure -cursor left_ptr
     961    $itk_component(drawing) itemconfigure $_cname2id($cname) \
     962        -image [Rappture::icon hotspot_normal]
     963}
     964
     965#
     966# Withdraw --
     967#
     968itcl::body Rappture::DrawingEntry::Withdraw { cname } {
    867969    Redraw
    868970}
     
    888990itcl::body Rappture::DrawingEntry::InitSubstitutions {} {
    889991    # Load a new parser with the variables representing the substitution
    890     set _parser [interp create -safe]
    891992    foreach name [array names _name2path] {
    892993        set path $_name2path($name)
     
    9031004itcl::body Rappture::DrawingEntry::XmlGet { path } {
    9041005    set value [$_owner xml get $path]
     1006    return [string trim $value]
     1007}
     1008
     1009itcl::body Rappture::DrawingEntry::XmlGetSubst { path } {
     1010    set value [$_owner xml get $path]
    9051011    if { $_parser == "" } {
    9061012        return $value
    9071013    }
    908     return [$_parser eval [list subst -nocommands $value]]
    909 }
    910 
     1014    return [string trim [$_parser eval [list subst -nocommands $value]]]
     1015}
     1016
     1017itcl::body Rappture::DrawingEntry::IsEnabled { path } {
     1018    set enable [string trim [$_owner xml get $path.about.enable]]
     1019    if {"" == $enable} {
     1020        return 1
     1021    }
     1022    if {![string is boolean $enable]} {
     1023        set re {([a-zA-Z_]+[0-9]*|\([^\(\)]+\)|[a-zA-Z_]+[0-9]*\([^\(\)]+\))(\.([a-zA-Z_]+[0-9]*|\([^\(\)]+\)|[a-zA-Z_]+[0-9]*\([^\(\)]+\)))*(:[-a-zA-Z0-9/]+)?}
     1024        set rest $enable
     1025        set enable ""
     1026        set deps ""
     1027        while {1} {
     1028            if {[regexp -indices $re $rest match]} {
     1029                foreach {s0 s1} $match break
     1030
     1031                if {[string index $rest [expr {$s0-1}]] == "\""
     1032                      && [string index $rest [expr {$s1+1}]] == "\""} {
     1033                    # string in ""'s? then leave it alone
     1034                    append enable [string range $rest 0 $s1]
     1035                    set rest [string range $rest [expr {$s1+1}] end]
     1036                } else {
     1037                    #
     1038                    # This is a symbol which should be substituted
     1039                    # it can be either:
     1040                    #   input.foo.bar
     1041                    #   input.foo.bar:units
     1042                    #
     1043                    set cpath [string range $rest $s0 $s1]
     1044                    set parts [split $cpath :]
     1045                    set ccpath [lindex $parts 0]
     1046                    set units [lindex $parts 1]
     1047
     1048                    # make sure we have the standard path notation
     1049                    set stdpath [$_owner regularize $ccpath]
     1050                    if {"" == $stdpath} {
     1051                        puts stderr "WARNING: don't recognize parameter $cpath in <enable> expression for $path.  This may be buried in a structure that is not yet loaded."
     1052                        set stdpath $ccpath
     1053                    }
     1054                    # substitute [_controlValue ...] call in place of path
     1055                    append enable [string range $rest 0 [expr {$s0-1}]]
     1056                    append enable [format {[ControlValue %s %s]} $stdpath $units]
     1057                    lappend deps $stdpath
     1058                    set rest [string range $rest [expr {$s1+1}] end]
     1059                }
     1060            } else {
     1061                append enable $rest
     1062                break
     1063            }
     1064        }
     1065    }
     1066    return [expr $enable]
     1067}
     1068
     1069# ----------------------------------------------------------------------
     1070# USAGE: ControlValue <path> ?<units>?
     1071#
     1072# Used internally to get the value of a control with the specified
     1073# <path>.  Returns the current value for the control.
     1074# ----------------------------------------------------------------------
     1075itcl::body Rappture::DrawingEntry::ControlValue {path {units ""}} {
     1076    if {"" != $_owner} {
     1077        set val [$_owner valuefor $path]
     1078         if {"" != $units} {
     1079            set val [Rappture::Units::convert $val -to $units -units off]
     1080        }
     1081        return $val
     1082    }
     1083    return ""
     1084}
     1085
     1086itcl::body Rappture::DrawingEntry::NumControlsEnabled { cname } {
     1087    set controls $_cname2controls($cname)
     1088    set count 0
     1089    foreach path $controls {
     1090        if { [IsEnabled $path] } {
     1091            incr count
     1092        }
     1093    }
     1094    return $count
     1095}
  • branches/blt4/gui/scripts/htmlviewer.tcl

    r2985 r3102  
    304304        if {"" != $node} {
    305305            set bbox [$itk_component(html) bbox $node]
    306             set realht [expr {[lindex $bbox 3]-[lindex $bbox 1]}]
     306            if { $bbox != "" } {
     307                set realht [expr {[lindex $bbox 3]-[lindex $bbox 1]}]
     308            }
    307309        }
    308310        if {$itk_option(-maxlines) > 0} {
  • branches/blt4/gui/scripts/vtkviewer.tcl

    r3068 r3102  
    13061306        }
    13071307        "glyphs" {
    1308             #SendCmd "glyphs colormap $colormap $tag"
     1308            SendCmd "glyphs colormap $colormap $tag"
     1309        }
     1310        "molecule" {
     1311            SendCmd "molecule colormap $colormap $tag"
    13091312        }
    13101313    }
  • branches/blt4/gui/src/Makefile.in

    r2742 r3102  
    5151OBJS            = \
    5252                RapptureGUI_Init.o \
     53                RpCanvHotspot.o \
    5354                RpCanvPlacard.o \
    5455                RpDiffview.o \
  • branches/blt4/gui/src/RapptureGUI_Init.c

    r2742 r3102  
    2323
    2424extern Tcl_AppInitProc Rappturegui_Init;
     25extern Tcl_AppInitProc RpCanvHotspot_Init;
    2526extern Tcl_AppInitProc RpCanvPlacard_Init;
     27extern Tcl_AppInitProc RpConvertDxToVtk_Init;
    2628extern Tcl_AppInitProc RpDiffview_Init;
    2729
     
    4850        return TCL_ERROR;
    4951    }
     52    if (RpCanvHotspot_Init(interp) != TCL_OK) {
     53        return TCL_ERROR;
     54    }
    5055    return TCL_OK;
    5156}
  • branches/blt4/gui/src/RpDiffview.c

    r2227 r3102  
    27742774        layoutPtr->lines = (DiffviewLayoutLine*)ckalloc(
    27752775            (unsigned)(layoutPtr->numLines * sizeof(DiffviewLayoutLine)));
     2776        layoutPtr->maxLines = layoutPtr->numLines;
    27762777    }
    27772778    layoutPtr->numLines = 0;
Note: See TracChangeset for help on using the changeset viewer.