# Program: xf
# Description: handle stripchart widgets
#
# $Header: Stripchart[2.3] Wed Mar 10 11:57:31 1993 garfield@garfield frozen $

global xfDefaultConf
set xfDefaultConf(stripchart) 4

##########
# Procedure: XFAdd.Stripchart
# Description: add a stripchart
# Arguments: xfW - the widget
#            xfName - a optional name
#            xfType - add or config
# Returns: none
# Sideeffects: none
##########
proc XFAdd.Stripchart {xfW xfName xfType} {
  global xfStatus

  XFEditSetStatus "Inserting Stripchart..."
  set xfName [XFMiscGetUniqueName $xfName stripchart]
  if {"$xfStatus(path)" == "."} {
    if {"$xfType" == "add"} {
      if {[catch "stripchart .$xfName" xfResult]} {
        XFProcError "$xfResult"
        XFEditSetStatus "Inserting Stripchart...aborted"
        return
      }
    } {
      if {[catch "stripchart .$xfName" xfResult]} {
        XFProcError "$xfResult"
        XFEditSetStatus "Inserting Stripchart...aborted"
        return
      }
    }

    XFMiscPositionWidget .$xfName
    XFMiscBindWidgetTree .$xfName
  } {
    if {"$xfType" == "add"} {
      if {[catch "stripchart $xfStatus(path).$xfName" xfResult]} {
        XFProcError "$xfResult"
        XFEditSetStatus "Inserting Stripchart...aborted"
        return
      }
    } {
      if {[catch "stripchart $xfStatus(path).$xfName" xfResult]} {
        XFProcError "$xfResult"
        XFEditSetStatus "Inserting Stripchart...aborted"
        return
      }
    }

    XFMiscPositionWidget $xfStatus(path).$xfName
    XFMiscBindWidgetTree $xfStatus(path).$xfName
  }

  incr xfStatus(elementCounter)
  XFEditSetPath $xfStatus(path)
  XFEditSetStatus "Inserting Stripchart...done"
}

##########
# Procedure: XFConfig.Stripchart4
# Description: configure a stripchart
# Arguments: xfW - the widget
#            xfType - config type (add or config)
#            xfClass - the class we configure
#            xfLeader - the leading window
# Returns: none
# Sideeffects: none
##########
proc XFConfig.Stripchart4 {xfW xfType xfClass {xfLeader ""}} {
  global xfStatus

  if {"$xfType" == "add"} {
    set xfName stripchart$xfStatus(elementCounter)
  } {
    set xfName [XFMiscPathName $xfW]
  }
  XFEditSetStatus "Calling parameter setting for Stripchart..."

  # build widget structure
  XFTmpltToplevel .xf${xfClass}Config4 400x610 \
    "Stripchart parameters:[XFMiscPathTail $xfW]" $xfLeader

  XFElementInit $xfW .xf${xfClass}Config4 $xfType $xfClass \
    XFStripchartSetStripchart4 parameters $xfName 4
  XFElementColor $xfW .xf${xfClass}Config4 $xfType $xfClass bg \
    background Background "Background" XFStripchartSetStripchart4
  XFElementBoolean $xfW .xf${xfClass}Config4 $xfType $xfClass up \
    "Draw up" XFStripchartSetStripchart4
  XFElementText $xfW .xf${xfClass}Config4 $xfType $xfClass interval \
    interval Interval "Interval" XFStripchartSetStripchart4
  XFElementScale $xfW .xf${xfClass}Config4 $xfType $xfClass numstrips \
    numstrips Numstrips "Numstrips" "" 1000 \
      XFStripchartSetStripchart4
  XFElementScale $xfW .xf${xfClass}Config4 $xfType $xfClass numticks \
    numticks Numticks "Numticks" "" 100 \
      XFStripchartSetStripchart4
  XFElementBoolean $xfW .xf${xfClass}Config4 $xfType $xfClass showticks \
    "Show ticks" XFStripchartSetStripchart4
  XFElementSize $xfW .xf${xfClass}Config4 $xfType $xfClass \
    XFStripchartSetStripchart4
  XFElementColor $xfW .xf${xfClass}Config4 $xfType $xfClass stripcolor \
    stripcolor Stripcolor "Strip color" XFStripchartSetStripchart4
  XFElementText $xfW .xf${xfClass}Config4 $xfType $xfClass title \
    title Title "Text" XFStripchartSetStripchart4
  XFElementColor $xfW .xf${xfClass}Config4 $xfType $xfClass textcolor \
    textcolor Foreground "Text color" XFStripchartSetStripchart4
  XFElementColor $xfW .xf${xfClass}Config4 $xfType $xfClass tickcolor \
    tickcolor Foreground "Tick color" XFStripchartSetStripchart4
  XFElementScaleDouble $xfW .xf${xfClass}Config4 $xfType \
    $xfClass value "Value" "Min" "Max" 1000 1000
  XFElementCommand $xfW .xf${xfClass}Config4 $xfType


  .xf${xfClass}Config4.params1.params2.value.value1.value1 set \
    [lindex [$xfW config -min] 4]
  .xf${xfClass}Config4.params1.params2.value.value2.value2 set \
    [lindex [$xfW config -max] 4]

  XFMiscSetResource \
    .xf${xfClass}Config4.params1.params2.value.value1.value1 \
      command "XFStripchartSetStripchart4 $xfW 0 $xfClass"
  XFMiscSetResource \
    .xf${xfClass}Config4.params1.params2.value.value2.value2 \
      command "XFStripchartSetStripchart4 $xfW 0 $xfClass"

  # save current parameter
  XFElementSave $xfW $xfClass {background interval numstrips numticks showticks stripcolor title textcolor tickcolor up max min width height command}

  # packing
  pack append .xf${xfClass}Config4.params1 \
              .xf${xfClass}Config4.params1.params2 {left fill expand}
  pack append .xf${xfClass}Config4 \
              .xf${xfClass}Config4.pathname {top fill frame center} \
              .xf${xfClass}Config4.leave {bottom fill} \
              .xf${xfClass}Config4.additional {bottom fill} \
              .xf${xfClass}Config4.params1 {top fill expand}

  XFBindFormConnect .xf${xfClass}Config4.params1.params2 \
    "XFStripchartSetStripchart4 $xfW 0 $xfClass"

  XFEditSetStatus "Calling parameter setting for Stripchart...done"
}

##########
# Procedure: XFStripchartSetStripchart4
# Description: set stripchart parameters
# Arguments: xfW - the widget
#            xfType - the type of setting (1 = set always, 0 = set
#                     only if permanent apply is on)
#            xfClass - the class we configure
#            xfParam1 - ignored parameter
# Returns: none
# Sideeffects: none
##########
proc XFStripchartSetStripchart4 {xfW xfType xfClass {xfParam1 ""}} {
  global xfConf
  global xfMisc

  if {$xfType == 0 && !$xfConf(applyParameters)} {
    return
  }
  if {"[info commands $xfW]" == ""} {
    return
  }
  XFMiscSetSymbolicName $xfW \
    [.xf${xfClass}Config4.params1.params2.symname.symname get]

  XFMiscSetResource $xfW background \
    [.xf${xfClass}Config4.params1.params2.bg.bg get]
  XFMiscSetResource $xfW command \
    [XFMiscGetText .xf${xfClass}Config4.params1.params2.command.command.command]
  if {"[.xf${xfClass}Config4.params1.params2.interval.interval get]" != ""} {
    XFMiscSetResource $xfW interval \
      [.xf${xfClass}Config4.params1.params2.interval.interval get]
  } {
    XFMiscSetResource $xfW interval 0
  }
  XFMiscSetResource $xfW max \
    [.xf${xfClass}Config4.params1.params2.value.value2.value2 get]
  XFMiscSetResource $xfW min \
    [.xf${xfClass}Config4.params1.params2.value.value1.value1 get]
  XFMiscSetResource $xfW numstrips \
    [.xf${xfClass}Config4.params1.params2.numstrips.numstrips get]
  XFMiscSetResource $xfW numticks \
    [.xf${xfClass}Config4.params1.params2.numticks.numticks get]
  XFMiscSetResource $xfW showticks $xfMisc(showticks)
  if {"[.xf${xfClass}Config4.params1.params2.stripcolor.stripcolor get]" != ""} {
    XFMiscSetResource $xfW stripcolor \
      [.xf${xfClass}Config4.params1.params2.stripcolor.stripcolor get]
  }
  XFMiscSetResource $xfW textcolor \
    [.xf${xfClass}Config4.params1.params2.textcolor.textcolor get]
  XFMiscSetResource $xfW tickcolor \
    [.xf${xfClass}Config4.params1.params2.tickcolor.tickcolor get]
  XFMiscSetResource $xfW title \
    [.xf${xfClass}Config4.params1.params2.title.title get]
  XFMiscSetResource $xfW up $xfMisc(up)
  XFMiscSetResource $xfW height \
    [.xf${xfClass}Config4.params1.params2.size.size2.size2 get]
  XFMiscSetResource $xfW width \
    [.xf${xfClass}Config4.params1.params2.size.size1.size1 get]
}

# eof

