#!/bin/sh
# the next line executes the program\
exec wish "$0" "$@"

# use this if your BWidget package is installed in user's space
# lappend auto_path /$env(HOME)/est/BWidget-1.8.0/

package require BWidget
package provide bddview 1.0

# ############################################
# $Revision: 14 $
# $Date: 2013-04-05 11:08:33 +0200 (pet, 05 apr 2013) $
#
# This file (bddview.tcl) is a Tcl/Tk script
# Author: Robert Meolic, meolic@uni-mb.si
#
# This file has been released into the public domain by
# the author.
#
# The author grants any entity the right to use this work
# for any purpose, without any conditions, unless such
# conditions are required by law.
#
# YOU NEED Tcl/Tk AND BWidget PACKAGE
# Both are included in ActiveTcl distribution
# Mac OS X: You can also use TclTk Aqua Batteries-Included
#
# http://www.tcl.tk/
# http://www.activestate.com/Products/activetcl/
# http://tcltkaqua.sourceforge.net/
# http://sourceforge.net/projects/tcllib/
# http://users.pandora.be/koen.vandamme1/tcl_tools/bwidgets/bwidgets.html
#
# bddview is used in Biddy project
# Homepage: http://lms.uni-mb.si/biddy/
#
# bddview is used in EST project
# Homepage: http://lms.uni-mb.si/EST/
#
# Updates of bddview from Robert Meolic
# are available in SVN repository:
# http://altair.uni-mb.si:8080/viewvc/
#
# USAGE:
# ./bddview.tcl example.bddview
#
# FORMAT:
# bddview reads BDD from the file with the
# following format:
#
# label <n> <name> <x> <y>
# node <n> <name> <x> <y>
# terminal <n> 1 <x> <y>
# connect <n1> <n2> <type>
#
# <n> is the unique number (integer)
# <name> is a string
# <x> and <y> are coordinates (integer)
# <type> is one of the following:
# s : single line
# si : inverted single line
# r : line to 'then' succesor
# l : line to 'else' successor
# li : inverted line to 'else' successor
# d : double line
#
# REMARKS:
# 1. (0,0) is top left corner.
# 2. Only one label is supported.
# 3. Single line (or inverted single line) should be
#    used to connect a label and a node.
# 4. Line to the right successor can not be inverted.
# 5. When using double line, the line to the left succesor
#    is always inverted.
#
# API (see near the end of file):
# proc not_implemented_yet { t }
# proc bddview_clear {}
# proc bddview_draw {name}
# proc bddview_saveas {win}
# proc bddview_print {win}
#
# Example (example.bddview):
# ---------------------------------------------------
# label 0 "Biddy" 100.0 10
# node 1 "B" 100 60
# node 2 "i" 100 125
# node 3 "d" 50 175
# terminal 4 1 50 240
# node 5 "y" 100 225
# terminal 6 1 100 290
# node 7 "d" 150 175
# terminal 8 1 150 240
# connect 0 1 s
# connect 1 2 d
# connect 2 3 l
# connect 2 7 r
# connect 3 4 l
# connect 3 5 r
# connect 5 6 d
# connect 7 5 l
# connect 7 8 r
#
# ---------------------------------------------------
# KNOWN BUGS:
# 1. none
#
# ############################################

set TITLE "BDDview, Robert Meolic"
set OS $tcl_platform(platform)

# DEBUGGING

# if {$tcl_platform(platform) == "windows"} {console show}
puts -nonewline "Starting $TITLE ... "

# ####################################################################
# IMAGES FOR TOOLBAR ICONS
#
# THEY ARE BASE64 ENCODED GIFS (32x32)
#
# --------------------------------------------------------------------
#
# Some images are from Kids Icons by Everaldo Coelho
#
# Obtained from:
# http://www.iconarchive.com/category/system/kids-icons-icons-by-everaldo.html
#
# License: Free for non-commercial use
#
# --------------------------------------------------------------------
#
# Some images are from Boomy toolbar icon set by Milosz Wlazlo
#
# Obtained from:
# http://www.iconarchive.com/category/application/boomy-icons-by-milosz-wlazlo.html
#
# License: Free for non-commercial use
#
# Details:
# All icons in the Boomy toolbar package are for personal use only.
# You may also use the icons in open source and freeware projects as
# long as you give credits to the author of the icons and link to his
# website (miloszwl.deviantart.com).
#
# The image data may be changed by You in a limited way, only by
# combining the included icons and adjusting hue, saturation, brightness.
#
# --------------------------------------------------------------------
#
# ####################################################################

set iconSave {
R0lGODlhIAAgAOf/AEhIeExLfE9SiFNSg1BTiVVUhVdVh1NWjVlXiVRailpY
illahV5YhVZcjFpbh1ddjV1bjlxdiF1eirNGIl9dkFpgkF5fi19gjGFfkWBh
jV1ik2JgkmFijmNhlGJjj7RNK2NkkGdki2RlkbVPMmVmkmdkmGZnlGlmmm1m
lGhplmprl2xpnWtsmWluoG9soLlZPnJulm9vnLtaP2xxpHVunXJvo3BxnnFy
n25zpXdwn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v5rX
psLCwqDZrsTExMXFxcbGxsfHx8jIyMzMzM3Nzc7OztHR0dLS0tPT07rlxLnn
vtbW1tfX19nZ2dra2tvb287n2d7e3uDg4OHh4eLi4uPj4+Xl5dbv3ubm5ufn
5+Pn+Ojo6Orq6t7y4+Hy5+zs7O3t7e7u7u/v7/Hx8fLy8vT09PX19ff39/j4
+Pn5+fr6+vT++Pz8/Pn+/P7+/v//////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/////////////////////yH5BAEKAP8ALAAAAAAgACAAAAj+AP8JHEiwoMGD
CBMqXPgPggkcOmCoaMGQ4YUiNSj8+4CiRo8eLCoedLAkxsEXRK5IiZJljch/
HZxEeCnSQpOZNCv+gJGz4oQcFXoynKCISQEKJ05M3IEDhVCBL5isuYSpqiM7
bd5cQtTjQggGLyHYqUp2kiNGaoAogQIJ06IkGxhW0MMGjJg6jiL5UVRIShZF
ZMnaKSIhYQqyjdJUAVPoT5M+gSNjgnQEwUEdkgJLesOEySOyeQ5JruoGbEEl
dDBVcoRI0KQmjMgCWiFjDlkuZMiiMXC6DCNGfuosKvMmMCUjGqZUNYPBhSWy
IQp6+HPlD5w3f6hIHjRjhI8nIHj+GKpK9UrBAGX6HEHzaAtkyV5s0CCBJPBq
OgkKSpDkZ0iSJqORJYcVkUVCyB4NGKSCaljo0EWAASrShx0JFgSAE1bdAEQh
ZFEFYR98fHHAQQdocUklmIxRgxOIVFXJi5fEGCMmjtRRxwkEIHQAE4h8xggV
MCxBxySqTWKkkZXoAYcQDyg0AAp1KNIWIljggAMWe0QSWCBg6GCCAgsBkMEY
fyTySCWQxMGElUE4gUUSLaAARAYVBQBBFngIskgjkFTSCB5OvCBCCUKEkYIA
LyWQwxl03KEHH3vY8QYaZaSBxQcF5DRABT9c8cUYY4CxxRVJqMAAoj0NUMAC
HJjAAgoRH0RwwABPEU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ih6MJFcAAhBoIELUpThBiGNFBLJ
wJuMojElenThRAYNCKBQAxN8UMMPeanhxr98uEGGF1MAQYIEChDAsEIKQHDB
CCK4AAQQOeSwQw0reGCBAwoYQMCxDCWQgAI5TXDBBBRccAFOCRBgANMYKeB0
0kkbIIDYGJVt9tkEBQQAOw==
}

image create photo icon.save.small
icon.save.small put $iconSave

image create photo icon.print.small
icon.print.small put $iconPrint

image create photo icon.pan.small
icon.pan.small put $iconPan

image create photo icon.zoom.small
icon.zoom.small put $iconZoom

image create photo icon.move.small
icon.move.small put $iconMove

image create photo icon.info.small
icon.info.small put $iconInfo

image create photo icon.left.small
icon.left.small put $iconLeft

image create photo icon.right.small
icon.right.small put $iconRight

image create photo icon.up.small
icon.up.small put $iconUp

image create photo icon.down.small
icon.down.small put $iconDown

image create photo icon.center.small
icon.center.small put $iconCenter

image create photo icon.exit.small
icon.exit.small put $iconExit

# ############################################
# INITIALIZATION
# ############################################

#STATE: pan, zoom, move, info
set STATE ""

#STATUSBAR: text in statusbar
set STATUSBAR ""

#XWIN,YWIN: initial size of canvas
set XWIN 1000
set YWIN 420

#ZOOM: initial 16
set ZOOM 16
set DOUBLELINE [expr $ZOOM/4.0]
set ARROWSIZE [expr round(2*sqrt($ZOOM))]
set INVSIZE [expr $ZOOM/8.0 + 1]

#XMAX,YMAX: $XMAX*$ZOOM and $YMAX*$ZOOM are max coordinates
#these are used to determine the size of box and grid
#min coordinates are always 0,0
#XMAX and YMAX are set in boxit, call boxit after every change
set XMAX [expr round($XWIN /$ZOOM)]
set YMAX [expr round($YWIN /$ZOOM)]

#SCROLL: x and y scroll increment
set SCROLL 8

#GRID
set GRIDON 0
set GRIDRESOLUTION 400
set GRID [expr $ZOOM * 8]

#ARROW
set ARROWSON 0
set ARROWSIZE 7

#BDD
set BDDNAME ""
array unset BDD
set BDDNODES ""
set TERMINALS ""

#these are used internal
set SELECTED ""
set TERMSELECTED ""
set LISTF ""
set LISTT ""
set DEPTH ""
set TERMDEPTH 0

# ############################################
# GUI
# ############################################

set COLORMENU gray80
set COLORTEXT "#90F0FF"
set COLORHIGH "#ffAA88"
set COLORBG "#FFE8C0"

set COLORGRID "#90A8CF"
set COLORNODE "#F8F8F0"
set COLORLEFT "#006828"
set COLORRIGHT "#002868"

wm title . $TITLE
wm iconname . BDDview

set mainframe [MainFrame .mainframe -bg $COLORMENU -textvariable STATUSBAR]
$mainframe.status.label configure -fg black
$mainframe showstatusbar status
pack $mainframe -fill both -expand yes

# CREATE TOOLBAR

set toolbarsize "small"
set toolbar [$mainframe addtoolbar]
$toolbar configure -bg $COLORMENU

set bb0 [ButtonBox $toolbar.bb0 -bg $COLORMENU -homogeneous 0 -spacing 4]
$bb0 add -image icon.save.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2 \
    -helptext "Save As" -command {bddview_saveas $mainwin}
$bb0 add -image icon.print.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2 \
    -helptext "Print to File" -command {bddview_print $mainwin}

pack $bb0 -side left -anchor w

set sep1 [Separator $toolbar.sep1 -bg $COLORMENU -orient vertical]
pack $sep1 -side left -fill y -padx 4 -anchor w

set bb1 [ButtonBox $toolbar.bb1 -bg $COLORMENU -homogeneous 0 -spacing 4]
$bb1 add -image icon.pan.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2 \
    -background $COLORMENU -helptext "Pan" -command {state pan $mainwin $bb1}
$bb1 add -image icon.zoom.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2 \
    -background $COLORMENU -helptext "Zoom" -command {state zoom $mainwin $bb1}
$bb1 add -image icon.move.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2 \
    -background $COLORMENU -helptext "Move" -command {state move $mainwin $bb1}
$bb1 add -image icon.info.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2 \
    -background $COLORMENU -helptext "Info" -command {state info $mainwin $bb1}

pack $bb1 -side left -anchor w

set sep2 [Separator $toolbar.sep2 -bg $COLORMENU -orient vertical]
pack $sep2 -side left -fill y -padx 4 -anchor w

set bb2 [ButtonBox $toolbar.bb2 -bg $COLORMENU -homogeneous 0 -spacing 4]
$bb2 add -image icon.left.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
    -helptext "Left" -command {compass "w" $mainwin}
$bb2 add -image icon.right.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
    -helptext "Right" -command {compass "e" $mainwin}
$bb2 add -image icon.up.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
    -helptext "Up" -command {compass "n" $mainwin}
$bb2 add -image icon.down.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
    -helptext "Down" -command {compass "s" $mainwin}
$bb2 add -image icon.center.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
    -helptext "Center" -command {compass "c" $mainwin}

pack $bb2 -side left -anchor w

set sep3 [Separator $toolbar.sep3 -bg $COLORMENU -orient vertical]
pack $sep3 -side left -fill y -padx 4 -anchor w

set bb3 [ButtonBox $toolbar.bb3 -bg $COLORMENU -homogeneous 0 -spacing 8]
$bb3 add -text "Arrows On/Off" -fg black -bg $COLORTEXT \
    -highlightbackground snow -highlightthickness 1 \
    -padx 4 -pady 2 -takefocus 0 -relief link -borderwidth 2 \
    -helptext "Arrows On/Off" -command {arrowsOnOff $mainwin $bb3}
$bb3 add -text "Grid On/Off" -fg black -bg $COLORTEXT \
    -highlightbackground snow -highlightthickness 1 \
    -padx 4 -pady 2 -takefocus 0 -relief link -borderwidth 2 \
    -helptext "Grid On/Off" -command {gridOnOff $mainwin $bb3}
$bb3 add -text "Grid +" -fg black -bg $COLORTEXT \
    -highlightbackground snow -highlightthickness 1 \
    -padx 4 -pady 2 -takefocus 0 -relief link -borderwidth 2 \
    -helptext "Grid +" -command {gridPlus $mainwin}
$bb3 add -text "Grid -" -fg black -bg $COLORTEXT \
    -highlightbackground snow -highlightthickness 1 \
    -padx 4 -pady 2 -takefocus 0 -relief link -borderwidth 2 \
    -helptext "Grid -" -command {gridMinus $mainwin}

pack $bb3 -side left -anchor w

set bb4 [ButtonBox $toolbar.bb4 -bg $COLORMENU -homogeneous 0 -spacing 2]
$bb4 add -image icon.exit.$toolbarsize \
    -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
    -helptext "Exit" -command {exit}

pack $bb4 -side right -anchor w

# CREATE SCROLLED CANVAS

set sc [ScrolledWindow $mainframe.scrolledcanvas -bg $COLORMENU -scrollbar both -auto none]
pack $sc -in [$mainframe getframe] -fill both -expand yes

set mainwin [$sc getframe].canvas
canvas $mainwin -bg $COLORBG -xscrollincrement $SCROLL -yscrollincrement $SCROLL -width $XWIN -height $YWIN
$sc setwidget $mainwin

# ENABLE MOUSE WHEEL
bind $mainwin <4> "%W yview scroll -5 units"
bind $mainwin <5> "%W yview scroll  5 units"
bind $mainwin <MouseWheel> {%W yview scroll [expr {-%D/120}] units}

set x [expr {([winfo screenwidth .] - [$mainwin cget -width]) / 2 - 8}]
set y 16
wm geometry . +$x+$y

# ############################################
# MOUSE ACTIONS
# ############################################

bind $mainwin <ButtonPress-1> {
  global X
  global Y
  global STATE
  global SELECTED
  global LISTF

  if {$STATE == "pan"} {
  }

  if {$STATE == "zoom"} {
    zoomIn $mainwin [$mainwin canvasx %x] [$mainwin canvasy %y]
  }

  if {$STATE == "move"} {
    set item [$mainwin gettags current]
    if {$item != ""} {
      set item [lindex $item 0]
      if {$item != "line"} {
        selectgraph $mainwin $item
        hidearrows $mainwin
        $mainwin itemconfigure "current&&outline" -activeoutline red
        foreach item $SELECTED {$mainwin itemconfigure $item -state disabled}
        foreach item $LISTF {
          $mainwin itemconfigure $item -state disabled
        }
      }
    }
  }

  if {$STATE == "info"} {
    set item [$mainwin gettags current]
    if {$item != ""} {
      set item [lindex $item 0]
      if {$item != "line"} {
        $mainwin itemconfigure "$item&&outline" -activeoutline red
        $mainwin itemconfigure "$item&&tekst" -state disabled
        $mainwin itemconfigure "$item&&outline" -state disabled
        drawinfo $mainwin $item [$mainwin canvasx %x] [$mainwin canvasy %y] 1
        foreach item $SELECTED {$mainwin itemconfigure $item -state disabled}
        foreach item $LISTF {
          $mainwin itemconfigure $item -state disabled
          $mainwin itemconfigure "i$item" -state disabled
          $mainwin itemconfigure "p$item" -state disabled
        }
      }
    }
  }

  set X %x
  set Y %y
}

bind $mainwin <ButtonRelease-1> {
  global STATE
  global SELECTED
  global LISTF
  global LISTT

  if {$STATE == "pan"} {
  }

  if {$STATE == "zoom"} {
  }

  if {$STATE == "move"} {
    boxit $mainwin
    fixedges $mainwin
    $mainwin itemconfigure "outline" -activeoutline black
    foreach item $SELECTED {$mainwin itemconfigure $item -state normal}
    foreach item $LISTF {
      $mainwin itemconfigure $item -state normal
    }
  }

  if {$STATE == "info"} {
    removeinfo $mainwin
    $mainwin itemconfigure "outline" -activeoutline black
    $mainwin itemconfigure "tekst" -state normal
    $mainwin itemconfigure "outline" -state normal
    foreach item $SELECTED {$mainwin itemconfigure $item -state normal}
    foreach item $LISTF {
      $mainwin itemconfigure $item -state normal
      $mainwin itemconfigure "i$item" -state normal
      $mainwin itemconfigure "p$item" -state normal
    }
  }

  set SELECTED ""
  set TERMSELECTED ""
  set LISTF ""
  set LISTT ""
}

bind $mainwin <B1-Motion> {
  global X
  global Y
  global STATE

  set xd [expr %x-$X]
  set yd [expr %y-$Y]

  if {$STATE == "pan"} {
    pan $mainwin $xd $yd
  }

  if {$STATE == "zoom"} {
  }

  if {$STATE == "move"} {
    if {[llength $SELECTED] > 0} {motion $mainwin $xd $yd}
  }

  if {$STATE == "info"} {
    $mainwin move info $xd $yd
  }

  set X %x
  set Y %y
}

bind $mainwin <ButtonPress-3> {
  global X
  global Y
  global STATE
  global SELECTED
  global LISTF

  if {$STATE == "pan"} {
    centerpoint $mainwin [$mainwin canvasx %x] [$mainwin canvasy %y]
  }

  if {$STATE == "zoom"} {
    zoomOut $mainwin [$mainwin canvasx %x] [$mainwin canvasy %y]
  }

  if {$STATE == "move"} {
    set item [$mainwin gettags current]
    if {$item != ""} {
      set item [lindex $item 0]
      if {$item != "line"} {
        selectnode $mainwin $item
        hidearrows $mainwin
        $mainwin itemconfigure "current&&outline" -activeoutline red
        foreach item $SELECTED {$mainwin itemconfigure $item -state disabled}
        foreach item $LISTF {
          $mainwin itemconfigure $item -state disabled
        }
      }
    }
  }

  if {$STATE == "info"} {
    set item [$mainwin gettags current]
    if {$item != ""} {
      set item [lindex $item 0]
      if {$item != "line"} {
        $mainwin itemconfigure "$item&&outline" -activeoutline red
        $mainwin itemconfigure "$item&&tekst" -state disabled
        $mainwin itemconfigure "$item&&outline" -state disabled
        drawinfo $mainwin $item [$mainwin canvasx %x] [$mainwin canvasy %y] 2
        foreach item $SELECTED {$mainwin itemconfigure $item -state disabled}
        foreach item $LISTF {
          $mainwin itemconfigure $item -state disabled
          $mainwin itemconfigure "i$item" -state disabled
          $mainwin itemconfigure "p$item" -state disabled
        }
        drawborder $mainwin
      }
    }
  }

  set X %x
  set Y %y
}

bind $mainwin <ButtonRelease-3> {
  global STATE
  global SELECTED
  global LISTF
  global LISTT

  if {$STATE == "pan"} {
  }

  if {$STATE == "zoom"} {
  }

  if {$STATE == "move"} {
    boxit $mainwin
    fixedges $mainwin
    $mainwin itemconfigure "outline" -activeoutline black
    foreach item $SELECTED {$mainwin itemconfigure $item -state normal}
    foreach item $LISTF {
      $mainwin itemconfigure $item -state normal
      $mainwin itemconfigure "i$item" -state normal
    }
  }

  if {$STATE == "info"} {
    removeinfo $mainwin
    removeborder $mainwin
    $mainwin itemconfigure "outline" -activeoutline black
    $mainwin itemconfigure "tekst" -state normal
    $mainwin itemconfigure "outline" -state normal
    foreach item $SELECTED {$mainwin itemconfigure $item -state normal}
    foreach item $LISTF {
      $mainwin itemconfigure $item -state normal
      $mainwin itemconfigure "i$item" -state normal
      $mainwin itemconfigure "p$item" -state normal
    }
  }

  set SELECTED ""
  set TERMSELECTED ""
  set LISTF ""
  set LISTT ""
}

bind $mainwin <B3-Motion> {
  global X
  global Y

  set xd [expr %x-$X]
  set yd [expr %y-$Y]

  if {$STATE == "pan"} {
  }

  if {$STATE == "zoom"} {
  }

  if {$STATE == "move"} {
    if {[llength $SELECTED] > 0} {motion $mainwin $xd $yd}
  }

  if {$STATE == "info"} {
    $mainwin move info $xd $yd
  }

  set X %x
  set Y %y
}

# ############################################
# CANVAS PROCEDURES
# ############################################

proc boxit {win} {
  global SELECTED
  global LISTF
  global LISTT
  global ZOOM
  global GRIDON
  global GRID
  global GRIDRESOLUTION
  global XMAX
  global YMAX

  removebox $win
  if {$GRIDON == 1} {removegrid $win}

  # REPAIR NEGATIVE COORDINATES (min = 2)

  set koord [$win bbox all]
  set x1 [lindex $koord 0]
  set y1 [lindex $koord 1]

  set nok 0
  if {$x1>2} {set x1 2} else {set nok [expr $nok + 1]}
  if {$y1>2} {set y1 2} else {set nok [expr $nok + 1]}

  if {$nok != 0} {motion $win [expr - $x1 + 2] [expr - $y1 + 2]}

  if {[llength $SELECTED] > 0} {

    # IF SOMETHING IS SELECTED THEN
    # SNAP TO GRID THE FIRST NODE IN THE SELECTION

    if {$GRIDON == 1} {

      set igrid [expr round($GRIDRESOLUTION*$ZOOM/$GRID)]
      set igrid2 [expr round($igrid/2)]

      set item [lindex $SELECTED 0]
      set koord [$win coords $item]
      set x1 [lindex $koord 0]
      set y1 [lindex $koord 1]
      set x2 [lindex $koord 2]
      set y2 [lindex $koord 3]

      set xc [expr round(($x1+$x2)/2)]
      set yc [expr round(($y1+$y2)/2)]

      if {$xc < $igrid} {
        set xg [expr $xc - $igrid]
      } else {
        set xg [expr $xc % $igrid]
        if {$xg > $igrid2} {set xg [expr $xg-$igrid]}
      }

      if {$yc < $igrid} {
        set yg [expr $yc - $igrid]
      } else {
        set yg [expr $yc % $igrid]
        if {$yg > $igrid2} {set yg [expr $yg-$igrid]}
      }

      # MOVE SELECTED NODES
      motion $win [expr -$xg] [expr -$yg]
    }

  }

  # set XMAX and YMAX

  set koord [$win bbox all]
  if {$koord == ""} {set koord [list 0 0 0 0]}
  set x2 [lindex $koord 2]
  set y2 [lindex $koord 3]
  set XMAX [expr round(1+(1.0*$x2)/$ZOOM)]
  set YMAX [expr round(1+(1.0*$y2)/$ZOOM)]

  $win configure -scrollregion [list 0 0 [expr 1+$XMAX*$ZOOM] [expr 1+$YMAX*$ZOOM]]

  drawbox $win
  if {$GRIDON == 1} {drawgrid $win}
}

proc centerpoint {win x y} {
  global ZOOM
  global XMAX
  global YMAX
  global SCROLL

  $win configure -xscrollincrement 1 -yscrollincrement 1

  if {$x > [expr $XMAX*$ZOOM/2.0]} {
    set x [expr $x - $XMAX*$ZOOM]
    $win xview moveto 1
    set offset [expr round($x + [$win canvasx 0])]
    if {$offset > 0} {set offset 0}
    $win xview scroll [expr round($x)] units
    set koord [$win xview]
    set x [expr ([lindex $koord 0]+[lindex $koord 1])/2.0]
    if {$x > 1} {set x 1}
    $win xview moveto $x
    $win xview scroll $offset units
  } else {
    $win xview moveto 0
    $win xview scroll [expr round($x)] units
    set offset [expr round($x - [$win canvasx 0])]
    set koord [$win xview]
    set x [expr (3*[lindex $koord 0]-[lindex $koord 1])/2.0]
    if {$x < 0} {set x 0}
    $win xview moveto $x
    $win xview scroll $offset units
  }

  if {$y > [expr $YMAX*$ZOOM/2.0]} {
    set y [expr $y - $YMAX*$ZOOM]
    $win yview moveto 1
    set offset [expr round($y + [$win canvasy 0])]
    if {$offset > 0} {set offset 0}
    $win yview scroll [expr round($y)] units
    set koord [$win yview]
    set y [expr ([lindex $koord 0]+[lindex $koord 1])/2.0]
    if {$y > 1} {set y 1}
    $win yview moveto $y
    $win yview scroll $offset units
  } else {
    $win yview moveto 0
    $win yview scroll [expr round($y)] units
    set offset [expr round($y - [$win canvasy 0])]
    set koord [$win yview]
    set y [expr (3*[lindex $koord 0]-[lindex $koord 1])/2.0]
    if {$y < 0} {set y 0}
    $win yview moveto $y
    $win yview scroll $offset units
  }

  $win configure -xscrollincrement $SCROLL -yscrollincrement $SCROLL
}

proc zoomIn {win px py} {
    global ZOOM
    global DOUBLELINE
    global ARROWSIZE
    global INVSIZE
    global GRIDON
    global GRID
    global LISTF
    global LISTT

    if {$ZOOM < 64} {

      removebox $win
      if {$GRIDON == 1} {removegrid $win}

      set LISTF [$win find withtag left]
      set LISTT [$win find withtag right]
      hidearrows $win

      set ZOOM [expr $ZOOM * 2]
      set DOUBLELINE [expr $ZOOM/4.0]
      set ARROWSIZE [expr round(2*sqrt($ZOOM))]
      set INVSIZE [expr $ZOOM/8.0 + 1]

      if {$GRIDON == 1} {
        gridPlus $win
      } else {
         if {$GRID<[expr $ZOOM*32]} {
           set GRID [expr $GRID*2]
         }
      }

      $win scale all 0 0 2 2
      $win itemconfigure tekst -font [list Courier $ZOOM]
      $win itemconfigure "left||right" \
        -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \

      boxit $win
      fixedges $win

      set LISTF ""
      set LISTT ""

      centerpoint $win [expr 2 * $px] [expr 2 * $py]

    }
}

proc zoomOut {win px py} {
    global ZOOM
    global DOUBLELINE
    global ARROWSIZE
    global INVSIZE
    global GRIDON
    global GRID
    global LISTF
    global LISTT

    if {$ZOOM > 1} {

      removebox $win
      if {$GRIDON == 1} {removegrid $win}

      set LISTF [$win find withtag left]
      set LISTT [$win find withtag right]
      hidearrows $win

      set ZOOM [expr $ZOOM / 2]
      set DOUBLELINE [expr $ZOOM/4.0]
      set ARROWSIZE [expr round(2*sqrt($ZOOM))]
      set INVSIZE [expr $ZOOM/8.0 + 1]

      if {$GRIDON == 1} {
        gridMinus $win
      } else {
         if {$GRID>[expr $ZOOM*4]} {
           set GRID [expr $GRID/2]
         }
      }

      $win scale all 0 0 0.5 0.5
      $win itemconfigure tekst -font [list Courier $ZOOM]
      $win itemconfigure "left||right" \
        -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \

      boxit $win
      fixedges $win

      set LISTF ""
      set LISTT ""

      centerpoint $win [expr $px/2.0] [expr $py/2.0]

    }
}

proc compass {direction win} {
  global ZOOM
  global SCROLL
  global XMAX
  global YMAX
  global XWIN
  global YWIN

  if {($direction == "w")} {
    $win xview moveto 0.0
  }

  if {($direction == "e")} {
    $win xview moveto 1.0
  }

  if {($direction == "n")} {
    $win yview moveto 0
  }

  if {($direction == "s")} {
    $win yview moveto 1
  }

  if {($direction == "c")} {
    set koord [$win bbox all]
    if {$koord == ""} {set koord [list 0 0 0 0]}
    set x [expr round(([lindex $koord 0]+[lindex $koord 2])/2.0)]
    set y [expr round(([lindex $koord 1]+[lindex $koord 3])/2.0)]
    centerpoint $win $x $y
  }

}

proc gridOnOff {win bb} {
  global GRIDON
  global COLORTEXT
  global COLORHIGH

  if {$GRIDON == 1} {
    $bb itemconfigure 1 -relief link -bg $COLORTEXT
    removegrid $win
    set GRIDON 0
  } else {
    $bb itemconfigure 1 -relief sunken -bg $COLORHIGH
    drawgrid $win
    set GRIDON 1
  }
}

proc gridPlus {win} {
  global ZOOM
  global GRID
  global GRIDON

  if {$GRIDON == 1} {
    if {$GRID<[expr $ZOOM*32]} {
      set GRID [expr $GRID*2]
      removegrid $win
      drawgrid $win
    }
  }
}

proc gridMinus {win} {
  global ZOOM
  global GRID
  global GRIDON

  if {$GRIDON == 1} {
    if {$GRID>[expr $ZOOM*4]} {
      set GRID [expr $GRID/2]
      removegrid $win
      drawgrid $win
    }
  }
}

proc drawbox {win} {
  global ZOOM
  global XMAX
  global YMAX

  $win create rectangle \
       0 0 [expr $XMAX*$ZOOM] [expr $YMAX*$ZOOM] \
       -outline blue -state normal \
       -tags [list line box]
}

proc removebox {win} {
  $win delete box
}

proc drawgrid {win} {
  global COLORGRID
  global GRIDRESOLUTION
  global ZOOM
  global XMAX
  global YMAX
  global GRID

  set igrid [expr round($GRIDRESOLUTION*$ZOOM/$GRID)]

  for {set i $igrid} {$i < [expr $YMAX*$ZOOM]} {set i [expr $i + $igrid]} {
    $win create line 0 $i [expr $XMAX*$ZOOM] $i \
      -fill $COLORGRID -dash "2 4" -state normal \
      -tags [list line grid]
  }

  for {set i $igrid} {$i < [expr $XMAX*$ZOOM]} {set i [expr $i + $igrid]} {
    $win create line $i 0 $i [expr $YMAX*$ZOOM] \
      -fill $COLORGRID -dash "2 4" -state normal \
      -tags [list line grid]
  }

  $win lower grid
}

proc removegrid {win} {
  $win delete grid
}

proc drawinfo {win item x y mode} {
  global SELECTED
  global TERMSELECTED
  global DEPTH
  global TERMDEPTH
  global BDD
  global LISTF
  global LISTT

  # mode 0: show info only
  # mode 1: show info + depth
  # mode 2: show info + coordinates

  set koord [$win bbox $item]
  set x [lindex $koord 2]
  set y [lindex $koord 3]

  set TERMDEPTH 0
  if { [lsearch -exact [$win gettags $item] "label"] != -1 } {
    foreach node [lindex [array get BDD $item] 1] {
      if {$node != "i"} {set variable [$win itemcget "$node && tekst" -text]}
    }
    addSelectedDepth $item 0
    set nodes -1
  } else {
    set variable [$win itemcget "$item && tekst" -text]
    addSelectedDepth $item 1
    set nodes 0
  }

  foreach item $TERMSELECTED {
    lappend SELECTED $item
    lappend DEPTH $item
    lappend DEPTH $TERMDEPTH
  }

  foreach item $SELECTED {
    set LISTF [concat $LISTF [$win find withtag [string replace $item 0 0 "f"]]]
    set LISTT [concat $LISTT [$win find withtag [string replace $item 0 0 "t"]]]
  }

  #puts "SELECTED"
  #puts $SELECTED
  #puts "TERMSELECTED"
  #puts $TERMSELECTED
  #puts "DEPTH"
  #puts $DEPTH

  set nodes [expr $nodes + [llength $SELECTED] - [llength $TERMSELECTED] + 1]

  set info1 "Root variable: "
  set info2 "BDD nodes: "
  set info3 "BDD terminal depth: "
  set info "$info1$variable\n$info2$nodes\n$info3$TERMDEPTH"

  $win create text $x $y \
     -text $info -font [list Helvetica 12 bold] -anchor w \
     -fill darkblue -state normal \
     -tags [list info]

  foreach item $SELECTED {
    set koord [$win bbox $item]
    set x1 [lindex $koord 0]
    set y1 [lindex $koord 1]
    set x2 [lindex $koord 2]
    set y2 [lindex $koord 3]

    if { $mode == 1 } {
      set infodepth [lindex $DEPTH [expr [lsearch -exact $DEPTH $item] + 1]]
      if {$infodepth != 0} {

        set infonum [string replace $item 0 0 "#"]
        $win create text $x2 [expr $y1-4] \
          -text $infonum -font [list Courier 10] -anchor e \
          -fill black -state normal \
          -tags [list infonum]

        $win create text [expr round($x1+0.95*($x2-$x1))] [expr round($y1+1.15*($y2-$y1))] \
          -text $infodepth -font [list Helvetica 10 bold] -anchor e \
          -fill black -state normal \
          -tags [list infonum]

      }
    }

    if { $mode == 2 } {

      set infonum [string replace $item 0 0 "#"]
      $win create text $x2 [expr $y1-4] \
        -text $infonum -font [list Courier 10] -anchor e \
        -fill black -state normal \
        -tags [list infonum]

      set infocoords "([expr round($x1+$x2)/2],[expr round($y1+$y2)/2])"
      $win create text $x1 [expr round($y1+1.15*($y2-$y1))] \
         -text $infocoords -font [list Helvetica 10] -anchor w \
         -fill black -state normal \
         -tags [list infonum]
    }

  }

  set DEPTH ""
}

proc removeinfo {win} {
  $win delete info
  $win delete infonum
}

proc drawborder {win} {
  global SELECTED

  foreach item $SELECTED {
    $win addtag selection withtag $item
  }

  set koord [$win bbox selection]
  set x1 [lindex $koord 0]
  set y1 [lindex $koord 1]
  set x2 [lindex $koord 2]
  set y2 [lindex $koord 3]

  $win create rectangle $x1 $y1 $x2 $y2 \
       -outline red -dash "2 4" -state normal \
       -tags [list line border]

  $win create rectangle \
       [expr $x1-2] [expr $y1-2] [expr $x1+2] [expr $y1+2]\
       -outline red -fill red -state normal \
       -tags [list line border]

  $win create rectangle \
       [expr $x2-2] [expr $y1-2] [expr $x2+2] [expr $y1+2]\
       -outline red -fill red -state normal \
       -tags [list line border]

  $win create rectangle \
       [expr $x1-2] [expr $y2-2] [expr $x1+2] [expr $y2+2]\
       -outline red -fill red -state normal \
       -tags [list line border]

  $win create rectangle \
       [expr $x2-2] [expr $y2-2] [expr $x2+2] [expr $y2+2]\
       -outline red -fill red -state normal \
       -tags [list line border]

  $win dtag selection
}

proc removeborder {win} {
  $win delete border
}

# ############################################
# DRAWING PROCEDURES
# ############################################

proc addTerminal {win num label x y} {
    global ZOOM
    global COLORNODE
    global BDDNODES
    global TERMINALS

    lappend BDDNODES [list $num $label "t"]
    lappend TERMINALS "n$num"

    set len [string length $label]
    set sizex [expr 7+$len*$ZOOM/2]
    set sizey [expr 7+$ZOOM/2]

    $win create rectangle \
       [expr $x-$sizex] [expr $y-$sizey] \
       [expr $x+$sizex] [expr $y+$sizey] \
       -outline black -activeoutline black -disabledoutline red -fill $COLORNODE -state normal \
       -tags [list "n$num" outline node]

    $win create text $x [expr $y+1] \
       -text $label -font [list Courier $ZOOM] -anchor center \
       -fill black -activefill black -disabledfill red -state normal \
       -tags [list "n$num" tekst node]
}

proc addNode {win num label x y} {
    global ZOOM
    global COLORNODE
    global BDDNODES

    lappend BDDNODES [list $num $label "n"]

    set len [string length $label]
    set sizex [expr 7+$len*$ZOOM/2]
    set sizey [expr 6+$ZOOM/2]

    $win create oval \
       [expr $x-$sizex] [expr $y-$sizey] \
       [expr $x+$sizex] [expr $y+$sizey] \
       -outline black -activeoutline black -disabledoutline red -fill $COLORNODE -state normal \
       -tags [list "n$num" outline node]

    $win create text $x [expr $y+1]\
       -text $label -font [list Courier $ZOOM] -anchor center \
       -fill black -activefill black -disabledfill red -state normal \
       -tags [list "n$num" tekst node]
}

proc addLabel {win num label x y} {
    global ZOOM
    global COLORBG
    global BDDNAME
    global BDDNODES

    set BDDNAME $label
    lappend BDDNODES [list $num $label "l"]

    set len [string length $label]
    set sizex [expr 7+$len*$ZOOM/2]
    set sizey [expr 6+$ZOOM/2]

    $win create oval \
       [expr $x-$sizex] [expr $y-$sizey] \
       [expr $x+$sizex] [expr $y+$sizey] \
       -outline $COLORBG -fill $COLORBG -state normal \
       -tags [list "n$num" outline node label]

    $win create text $x [expr $y+1]\
       -text $label -font [list Courier $ZOOM] -anchor center \
       -fill black -activefill black -disabledfill red -state normal \
       -tags [list "n$num" tekst node label]
}

proc addPoint {win x y tag} {
    $win create oval \
       [expr $x] [expr $y] [expr $x+1] [expr $y+1] \
       -outline black -activeoutline red -disabledoutline red -state normal \
       -tags [list line $tag node]
}

proc connect {win num1 num2 type} {
    global ZOOM
    global BDD
    global ARROWSIZE
    global COLORLEFT
    global COLORRIGHT

    set item [lindex [array get BDD "n$num1"] 1]

    set koord1 [$win bbox "n$num1"]
    set koord2 [$win bbox "n$num2"]

    set center1x [expr ([lindex $koord1 0]+[lindex $koord1 2])/2]
    set center1y [expr ([lindex $koord1 1]+[lindex $koord1 3])/2]

    set center2x [expr ([lindex $koord2 0]+[lindex $koord2 2])/2]
    set center2y [expr ([lindex $koord2 1]+[lindex $koord2 3])/2]

    if {$type == "l"} {
      set item [linsert $item 0 "n$num2"]
      $win create line $center1x $center1y $center2x $center2y \
         -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
         -width 1 -fill $COLORLEFT -disabledfill red -state normal \
         -tags [list line "f$num1" "t$num2" left node]
    }

    if {$type == "li"} {
      set item [linsert $item 0 "n$num2"]
      set item [linsert $item 0 "i"]
      $win create line $center1x $center1y $center2x $center2y \
       -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
       -width 1 -fill $COLORLEFT -disabledfill red -state normal \
       -tags [list line "f$num1" "t$num2" left inverted node]
    }

    if {$type == "r"} {
      set item [linsert $item end "n$num2"]
      $win create line $center1x $center1y $center2x $center2y \
         -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
         -width 1 -fill $COLORRIGHT -disabledfill red -state normal \
         -tags [list line "f$num1" "t$num2" right node]
    }

    if {$type == "s"} {
      set item [linsert $item 0 "n$num2"]
      $win create line $center1x $center1y $center2x $center2y \
         -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
         -width 1 -fill black -disabledfill red -state normal \
         -tags [list line "f$num1" "t$num2" left right node]
    }

    if {$type == "si"} {
      set item [linsert $item 0 "n$num2"]
      set item [linsert $item 0 "i"]
      $win create line $center1x $center1y $center2x $center2y \
         -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
         -width 1 -fill black -disabledfill red -state normal \
         -tags [list line "f$num1" "t$num2" left right inverted node]
    }

    if {$type == "d"} {
      set item "n$num2"
      $win create line [expr $center1x] [expr $center1y] \
                       [expr $center2x] [expr $center2y] \
         -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
         -width 1 -fill $COLORLEFT -disabledfill red -stipple "" -state normal \
         -tags [list line "f$num1" "t$num2" left double inverted node]
      $win create line [expr $center1x] [expr $center1y] \
                       [expr $center2x] [expr $center2y] \
         -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
         -width 1 -fill $COLORRIGHT -disabledfill red -state normal \
         -tags [list line "f$num1" "t$num2" right double node]
    }

    if {$type == "dequal"} {
      set item "n$num2"
      $win create line [expr $center1x] [expr $center1y] \
                       [expr $center2x] [expr $center2y] \
         -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
         -width 1 -fill $COLORLEFT -disabledfill red -stipple "" -state normal \
         -tags [list line "f$num1" "t$num2" left double node]
      $win create line [expr $center1x] [expr $center1y] \
                       [expr $center2x] [expr $center2y] \
         -arrow none -arrowshape [list $ARROWSIZE $ARROWSIZE [expr $ARROWSIZE/2]] \
         -width 1 -fill $COLORRIGHT -disabledfill red -state normal \
         -tags [list line "f$num1" "t$num2" right double node]
    }

    $win lower line

    array set BDD [list "n$num1" $item]
}

proc parsefile {win filename} {
  set f [open $filename r]

  while {[gets $f line] >= 0} {
    if {$line != ""} {
      set i 0
      set end 0
      while {$end < [string length $line]} {
        set line [string range $line $end end]
        set line [string trim $line]
        set end [string first " " $line 0]
        if {$end == -1} {
          set end [string length $line]
        }
        set word [string range $line 0 [expr $end -1]]
        set "arg$i" $word
        set i [expr $i+1]
      }

      if {$arg0 == "node"} {
        set arg2 [string map {\" ""} $arg2]
        addNode $win $arg1 $arg2 $arg3 $arg4
      }

      if {$arg0 == "terminal"} {
        set arg2 [string map {\" ""} $arg2]
        addTerminal $win $arg1 $arg2 $arg3 $arg4
      }

      if {$arg0 == "label"} {
        set arg2 [string map {\" ""} $arg2]
        addLabel $win $arg1 $arg2 $arg3 $arg4
      }

      if {$arg0 == "connect"} {
        connect $win $arg1 $arg2 $arg3
      }
    }
  }

  close $f
}

# ############################################
# USER PROCEDURES
# ############################################

proc state {s win bb} {
  global STATE
  global STATUSBAR
  global COLORMENU
  global COLORHIGH

  if {$s != $STATE} {
    switch $STATE {
      pan {$bb itemconfigure 0 -relief link -background $COLORMENU}
      zoom {$bb itemconfigure 1 -relief link -background $COLORMENU}
      move {$bb itemconfigure 2 -relief link -background $COLORMENU}
      info {$bb itemconfigure 3 -relief link -background $COLORMENU}
    }
    switch $s {
      pan {
             $win itemconfigure "tekst" -activefill black
             $win itemconfigure "outline" -activeoutline black
             $bb itemconfigure 0 -relief sunken -background $COLORHIGH
             $win configure -cursor hand2
             set STATUSBAR "\[Pan\]  Left button + drag = scroll  /  Right button = center"
           }
      zoom {
             $win itemconfigure "tekst" -activefill black
             $win itemconfigure "outline" -activeoutline black
             $bb itemconfigure 1 -relief sunken -background $COLORHIGH
             $win configure -cursor target
             set STATUSBAR "\[Zoom\]  Left button = zoom in  /  Right button = zoom out"
           }
      move {
             $win itemconfigure "tekst" -activefill red
             $win itemconfigure "outline" -activeoutline black
             $bb itemconfigure 2 -relief sunken -background $COLORHIGH
             $win configure -cursor fleur
             set STATUSBAR "\[Move\]  Left button + drag = move subgraph  /  Right button + drag = move node"
           }
      info {
             $win itemconfigure "tekst" -activefill red
             $win itemconfigure "outline" -activeoutline black
             $bb itemconfigure 3 -relief sunken -background $COLORHIGH
             $win configure -cursor arrow
             set STATUSBAR "\[Info\]  Left button = subgraph info /  Right button = subgraph bounding box"
           }
    }
    set STATE $s
  }
}

proc selectnode {win item} {
  global SELECTED
  global LISTF
  global LISTT

  set SELECTED [list $item]
  set LISTF [$win find withtag [string replace $item 0 0 "f"]]
  set LISTT [$win find withtag [string replace $item 0 0 "t"]]
}

proc addSelected {root} {
  global SELECTED
  global TERMSELECTED
  global BDD
  global TERMINALS

  if { [lsearch -exact $SELECTED $root] == -1 } {
    lappend SELECTED $root
    if { [lsearch -exact $TERMINALS $root] != -1 } {
      lappend TERMSELECTED $root
    } else {
      foreach item [lindex [array get BDD $root] 1] {
        if {$item != "i"} {addSelected $item}
      }
    }
  }
}

proc addSelectedDepth {root num} {
  global SELECTED
  global TERMSELECTED
  global DEPTH
  global TERMDEPTH
  global BDD
  global TERMINALS

  if { [lsearch -exact $TERMINALS $root] != -1 } {
    if {$TERMDEPTH == 0} {
      set TERMDEPTH $num
    } elseif {$num > $TERMDEPTH} {
      set TERMDEPTH $num
    }
    if { [lsearch -exact $TERMSELECTED $root] == -1 } {
      lappend TERMSELECTED $root
    }
  } elseif { [lsearch -exact $SELECTED $root] == -1 } {
    lappend SELECTED $root
    lappend DEPTH $root
    lappend DEPTH $num
    foreach item [lindex [array get BDD $root] 1] {
      if {$item != "i"} {addSelectedDepth $item [expr $num + 1]}
    }
  } else {
    set i [expr [lsearch -exact $DEPTH $root] + 1]
    set inum [lindex $DEPTH $i]
    if {$num > $inum} {
      set DEPTH [lreplace $DEPTH $i $i $num]
      foreach item [lindex [array get BDD $root] 1] {
        if {$item != "i"} {addSelectedDepth $item [expr $num + 1]}
      }
    }
  }
}

proc selectgraph {win item} {
  global SELECTED
  global LISTF
  global LISTT

  addSelected $item
  foreach item $SELECTED {
    set LISTF [concat $LISTF [$win find withtag [string replace $item 0 0 "f"]]]
    set LISTT [concat $LISTT [$win find withtag [string replace $item 0 0 "t"]]]
  }
}

proc pan {win xd yd} {
  global SCROLL

  $win xview scroll [expr round((-1.0*$xd)/(2.0*$SCROLL))] units
  $win yview scroll [expr round((-1.0*$yd)/(2.0*$SCROLL))] units
}

proc motion {win xd yd} {
  global SELECTED
  global LISTF
  global LISTT

  if {[llength $SELECTED] > 0} {

    foreach item $SELECTED {
      $win move $item $xd $yd
    }

    foreach item $LISTF {
      set koord [$win coords $item]
      set x1 [lindex $koord 0]
      set y1 [lindex $koord 1]
      set x2 [lindex $koord 2]
      set y2 [lindex $koord 3]

      set x1 [expr $x1+$xd]
      set y1 [expr $y1+$yd]

      $win coords $item $x1 $y1 $x2 $y2
    }

    foreach item $LISTT {
      set koord [$win coords $item]
      set x1 [lindex $koord 0]
      set y1 [lindex $koord 1]
      set x2 [lindex $koord 2]
      set y2 [lindex $koord 3]

      set x2 [expr $x2+$xd]
      set y2 [expr $y2+$yd]

      $win coords $item $x1 $y1 $x2 $y2
    }

  } else {

    foreach item [$win find withtag node] {
      $win move $item $xd $yd
    }

  }
}

proc fixedgenode {win item tags dir a b dx dy} {
  global XARROW #used as parameter called by reference
  global YARROW #used as parameter called by reference
  global DOUBLELINE

  if {[lsearch -exact $tags "double"] == -1} {
    set diff [expr sqrt($dy*$dy*$a*$a+$dx*$dx*$b*$b)]
    set S [expr ($dy*$a)/$diff]
    set C [expr ($dx*$b)/$diff]
    set XARROW [expr $XARROW + $dir*$a*$C]
    set YARROW [expr $YARROW - $dir*$b*$S]
  } else {
    set diff [expr sqrt($dy*$dy+$dx*$dx)]
    set S [expr $dy/$diff]
    set C [expr $dx/$diff]
    set pa [expr $b*$b*$C*$C-$DOUBLELINE*$DOUBLELINE]
    set pb [expr $a*$b*$S*$C]
    set pd [expr $a*$a*$S*$S+$pa]
    if {[lsearch -exact $tags "left"] != -1} {
      set sign -1
      if {([expr $dir*$dx] < 0)&&($pa < 0)&&([expr $dir*$pb] < 0)} {set sign +1}
      if {([expr $dir*$dx] >= 0)&&!(($pa < 0)&&([expr $dir*$pb] < 0))} {set sign +1}
      if {([expr $dy] < 0)&&($pa < 0)&&($pb == 0)} {set sign -1}
      set angle [expr atan((-$pb+$dir*$DOUBLELINE*sqrt($pd))/$pa)]
      set XARROW [expr $XARROW + $sign*$a*cos($angle)]
      set YARROW [expr $YARROW + $sign*$b*sin($angle)]
    }
    if {[lsearch -exact $tags "right"] != -1} {
      set sign -1
      if {([expr $dir*$dx] < 0)&&($pa < 0)&&([expr $dir*$pb] >= 0)} {set sign +1}
      if {([expr $dir*$dx] >= 0)&&!(($pa < 0)&&([expr $dir*$pb] >= 0))} {set sign +1}
      if {([expr $dy] < 0)&&($pa < 0)&&($pb == 0)} {set sign +1}
      set angle [expr atan((-$pb-$dir*$DOUBLELINE*sqrt($pd))/$pa)]
      set XARROW [expr $XARROW + $sign*$a*cos($angle)]
      set YARROW [expr $YARROW + $sign*$b*sin($angle)]
    }
  }
}

proc fixedgeterminal {win item tags dir a b dx dy} {
  global XARROW #used as parameter called by reference
  global YARROW #used as parameter called by reference
  global DOUBLELINE

  if {$dx == 0} {
    if {[lsearch -exact $tags "double"] == -1} {
      set n 0
    } else {
      if {[lsearch -exact $tags "left"] == -1} {
        set n [expr -$DOUBLELINE]
      }
      if {[lsearch -exact $tags "right"] == -1} {
        set n [expr +$DOUBLELINE]
      }
    }
    if {$dy < 0} {set sign -1} else {set sign +1}
    set XARROW [expr $XARROW + $sign*$n]
    set YARROW [expr $YARROW + $sign*$b]
  }

  if {$dy == 0} {
    if {[lsearch -exact $tags "double"] == -1} {
      set n 0
    } else {
      if {[lsearch -exact $tags "left"] == -1} {
        set n [expr -$DOUBLELINE]
      }
      if {[lsearch -exact $tags "right"] == -1} {
        set n [expr +$DOUBLELINE]
      }
    }
    if {$dx < 0} {set sign -1} else {set sign +1}
    set XARROW [expr $XARROW - $sign*$a]
    set YARROW [expr $YARROW + $sign*$n]
  }

  if {($dx != 0) && ($dy != 0)} {

    set k [expr ($dy/$dx)]

    if {[lsearch -exact $tags "double"] == -1} {
      set n 0
    } else {
      if {[lsearch -exact $tags "left"] == -1} {
        set n [expr -$DOUBLELINE*sqrt(1+$k*$k)]
      }
      if {[lsearch -exact $tags "right"] == -1} {
        set n [expr +$DOUBLELINE*sqrt(1+$k*$k)]
      }
    }

    if {$dx < 0} {
      set n [expr -$n]
      set a [expr -$a]
    }
    if {$dy < 0} {
      set b [expr -$b]
    }

    set xdiff [expr abs(($b-$n)/$k)]
    set ydiff [expr abs($a*$k+$n)]

    if {([expr abs($b)] > $ydiff) || ([expr abs($a)] < $xdiff)} {
      set XARROW [expr $XARROW - $a]
      set YARROW [expr $YARROW + $a*$k+$n]
    } else {
      set XARROW [expr $XARROW - ($b-$n)/$k]
      set YARROW [expr $YARROW + $b]
    }
  }
}

# THIS IS USED TO RESTORE EDGES BETWEEN NODES
# FUNCTION ALSO CREATES INVERTERS
proc fixedges {win} {
  global XARROW #used as parameter called by reference
  global YARROW #used as parameter called by reference
  global LISTF
  global LISTT
  global COLORLEFT
  global COLORRIGHT
  global INVSIZE

  foreach item $LISTF {$win addtag selection withtag $item}
  foreach item $LISTT {$win addtag selection withtag $item}
  $win itemconfigure "selection&&double&&left" -stipple ""
  $win itemconfigure "selection&&double" -width 1
  $win itemconfigure "selection&&inverted" -width 1
  set list [$win find withtag selection]
  $win dtag selection

  set allitem ""
  while {$list != ""} {

  set allitem [concat $allitem $list]
  set otherlist ""

  foreach item $list {
    $win delete "p$item"
    $win delete "i$item"

    set tags [$win gettags $item]
    set node1 [string replace [lindex $tags 1] 0 0 "n"]
    set node2 [string replace [lindex $tags 2] 0 0 "n"]

    set koord1 [$win bbox $node1]
    set koord2 [$win bbox $node2]

    set xarrow1 [expr ([lindex $koord1 0] + [lindex $koord1 2])/2.0]
    set yarrow1 [expr ([lindex $koord1 1] + [lindex $koord1 3])/2.0]
    set xarrow2 [expr ([lindex $koord2 0] + [lindex $koord2 2])/2.0]
    set yarrow2 [expr ([lindex $koord2 1] + [lindex $koord2 3])/2.0]

    set dx [expr $xarrow2 - $xarrow1]
    set dy [expr $yarrow1 - $yarrow2]
    if {($dx == 0)&&($dy == 0)} {set dx 1}

    if {([lsearch -exact $tags "double"] == -1) &&
        ([lsearch -exact $tags "left"] != -1)} {

      set oline [$win find withtag "[lindex $tags 1]&&right"]
      if {[lsearch -exact $allitem $oline] == -1} {
        lappend otherlist $oline
      }
    }

    if {([lsearch -exact $tags "double"] == -1) &&
        ([lsearch -exact $tags "right"] != -1)} {

      set oline [$win find withtag "[lindex $tags 1]&&left"]
      if {[lsearch -exact $allitem $oline] == -1} {
        lappend otherlist $oline
      }
    }

    # edge's start

    set point 0

    if {([lsearch -exact $tags "double"] == -1) &&
        ([lsearch -exact $tags "left"] != -1) && ($dy < 0)} \
    {
      set other [$win gettags "[lindex $tags 1]&&right"]
      set onode [$win bbox [string replace [lindex $other 2] 0 0 "n"]]
      set oxarrow2 [expr ([lindex $onode 0] + [lindex $onode 2])/2.0]
      set oyarrow2 [expr ([lindex $onode 1] + [lindex $onode 3])/2.0]
      set odx [expr $oxarrow2 - $xarrow1]
      set ody [expr $yarrow1 - $oyarrow2]
      if {($odx == 0)&&($ody == 0)} {set odx 1}

      if {([expr $dy*$odx] > [expr $dx*$ody]) && ($ody < 0)} {

        set point [expr abs([lindex $koord1 1]-[lindex $koord1 3])]
#        addPoint $win [expr $yarrow1+$point] [expr $xarrow1-$point] "p$item"

        $win create line $xarrow1 $yarrow1 [expr $xarrow1-$point] [expr $yarrow1+$point] \
           -arrow none -width 1 -fill $COLORLEFT -disabledfill red -state normal \
           -tags [list line "p$item" node]

        $win lower "p$item"

        if {([lsearch -exact $tags "inverted"] != -1)} {
          $win create oval \
            [expr (8*$xarrow1-5*$point)/8-$INVSIZE] [expr (8*$yarrow1+5*$point)/8-$INVSIZE] \
            [expr (8*$xarrow1-5*$point)/8+$INVSIZE] [expr (8*$yarrow1+5*$point)/8+$INVSIZE] \
            -outline $COLORLEFT -disabledoutline red \
            -fill $COLORLEFT -disabledfill red -state normal \
            -tags [list line "i$item" node]
        }

        set xarrow1 [expr $xarrow1-$point]
        set yarrow1 [expr $yarrow1+$point]

        set dx [expr $xarrow2 - $xarrow1]
        set dy [expr $yarrow1 - $yarrow2]
        if {($dx == 0)&&($dy == 0)} {set dx 1}
      }
    }

    if {([lsearch -exact $tags "double"] == -1) &&
        ([lsearch -exact $tags "right"] != -1) && ($dy < 0)} \
    {

      set other [$win gettags "[lindex $tags 1]&&left"]
      set other [$win bbox [string replace [lindex $other 2] 0 0 "n"]]
      set oxarrow2 [expr ([lindex $other 0] + [lindex $other 2])/2.0]
      set oyarrow2 [expr ([lindex $other 1] + [lindex $other 3])/2.0]
      set odx [expr $oxarrow2 - $xarrow1]
      set ody [expr $yarrow1 - $oyarrow2]
      if {($odx == 0)&&($ody == 0)} {set odx 1}

      if {([expr $dy*$odx] < [expr $dx*$ody]) && ($ody < 0)} {

        set point [expr abs([lindex $koord1 1]-[lindex $koord1 3])]
#        addPoint $win [expr $yarrow1+$point] [expr $xarrow1+$point] "p$item"

        $win create line $xarrow1 $yarrow1 [expr $xarrow1+$point] [expr $yarrow1+$point] \
           -arrow none -width 1 -fill $COLORRIGHT -disabledfill red -state normal \
           -tags [list line "p$item" node]

        $win lower "p$item"

        set xarrow1 [expr $xarrow1+$point]
        set yarrow1 [expr $yarrow1+$point]

        set dx [expr $xarrow2 - $xarrow1]
        set dy [expr $yarrow1 - $yarrow2]
        if {($dx == 0)&&($dy == 0)} {set dx 1}
      }
    }

    if {$point == 0} {
      set XARROW $xarrow1
      set YARROW $yarrow1
      set a [expr ([lindex $koord1 2] - [lindex $koord1 0])/2.0]
      set b [expr ([lindex $koord1 3] - [lindex $koord1 1])/2.0]
      if {[$win type $node1] == "oval"} {
        fixedgenode $win $item $tags 1 $a $b $dx $dy
      }
      if {[$win type $node1] == "rectangle"} {
        fixedgeterminal $win $item $tags 1 $a $b $dx $dy
      }
      set xarrow1 $XARROW
      set yarrow1 $YARROW
    }

    # edge's end

    set XARROW $xarrow2
    set YARROW $yarrow2
    set a [expr ([lindex $koord2 2] - [lindex $koord2 0])/2.0]
    set b [expr ([lindex $koord2 3] - [lindex $koord2 1])/2.0]
    if {[$win type $node2] == "oval"} {
      fixedgenode $win $item $tags -1 $a $b $dx $dy
    }
    if {[$win type $node2] == "rectangle"} {
      fixedgeterminal $win $item $tags -1 $a $b $dx $dy
    }
    set xarrow2 $XARROW
    set yarrow2 $YARROW

    $win coords $item $xarrow1 $yarrow1 $xarrow2 $yarrow2

    if {$point == 0} {
      if {([lsearch -exact $tags "inverted"] != -1)} {
        $win create oval \
           [expr (5*$xarrow1+3*$xarrow2)/8-$INVSIZE] [expr (5*$yarrow1+3*$yarrow2)/8-$INVSIZE] \
           [expr (5*$xarrow1+3*$xarrow2)/8+$INVSIZE] [expr (5*$yarrow1+3*$yarrow2)/8+$INVSIZE] \
           -outline $COLORLEFT -disabledoutline red \
           -fill $COLORLEFT -disabledfill red -state normal \
           -tags [list line "i$item" node]
      }
    }
  }

  set list $otherlist
  }
}

# THIS IS USED TO CREATE SIMPLE EDGES BETWEEN NODES CENTER
# POINTS ARE DELETED, USE FIXEDGES TO RESTORE THEM
proc hidearrows {win} {
  global LISTF
  global LISTT
  global DOUBLELINE

  foreach item $LISTF {$win addtag selection withtag $item}
  foreach item $LISTT {$win addtag selection withtag $item}
  $win itemconfigure "selection&&double&&left" \
    -width [expr 2*$DOUBLELINE+2] -stipple gray50
  $win itemconfigure "selection&&double&&right" -width 2
  $win itemconfigure "selection&&!double&&inverted" -width 2
  set list [$win find withtag "selection"]
  $win dtag selection

  foreach item $list {
    set tags [$win gettags $item]

    set koord1 [$win bbox [string replace [lindex $tags 1] 0 0 "n"]]
    set koord2 [$win bbox [string replace [lindex $tags 2] 0 0 "n"]]

    set xarrow1 [expr ([lindex $koord1 0] + [lindex $koord1 2])/2.0]
    set yarrow1 [expr ([lindex $koord1 1] + [lindex $koord1 3])/2.0]
    set xarrow2 [expr ([lindex $koord2 0] + [lindex $koord2 2])/2.0]
    set yarrow2 [expr ([lindex $koord2 1] + [lindex $koord2 3])/2.0]

    $win delete "p$item"
    $win delete "i$item"
    $win coords $item $xarrow1 $yarrow1 $xarrow2 $yarrow2
  }
}

proc noarrows {win} {
  $win itemconfigure "left||right" -arrow none
}

proc showarrows {win} {
  $win itemconfigure "left||right" -arrow last
}

proc arrowsOnOff {win bb} {
  global ARROWSON
  global COLORTEXT
  global COLORHIGH

  if {$ARROWSON == 1} {
    $bb itemconfigure 0 -relief link -bg $COLORTEXT
    noarrows $win
    set ARROWSON 0
  } else {
    $bb itemconfigure 0 -relief sunken -bg $COLORHIGH
    showarrows $win
    set ARROWSON 1
  }
}

# ############################################
# API
# ############################################

proc not_implemented_yet { t } {
  tk_messageBox -icon info -message "$t" -type ok
}

proc bddview_clear {} {
  global mainwin

  global BDDNAME
  global BDD
  global BDDNODES
  global TERMINALS

  global X
  global Y

  global SELECTED
  global TERMSELECTED
  global LISTF
  global LISTT
  global DEPTH
  global TERMDEPTH

  $mainwin delete all

  set BDDNAME ""
  array unset BDD
  set BDDNODES ""
  set TERMINALS ""

  set SELECTED ""
  set TERMSELECTED ""
  set LISTF ""
  set LISTT ""
  set DEPTH ""
  set TERMDEPTH 0
}

proc bddview_draw {name} {
  global mainwin
  global ZOOM
  global ARROWSON
  global LISTF
  global LISTT

  bddview_clear

  set activezoom $ZOOM

  while {$ZOOM > 16} {
    zoomOut $mainwin 0 0
  }

  while {$ZOOM < 16} {
    zoomIn $mainwin 0 0
  }

  parsefile $mainwin $name
  boxit $mainwin

  set LISTF [$mainwin find withtag left]
  set LISTT [$mainwin find withtag right]
  fixedges $mainwin

  set LISTF ""
  set LISTT ""

  while {$ZOOM > $activezoom} {
    zoomOut $mainwin 0 0
  }

  while {$ZOOM < $activezoom} {
    zoomIn $mainwin 0 0
  }

  compass "c" $mainwin
  compass "n" $mainwin

  if {$ARROWSON == 1} {
    showarrows $mainwin
  }

}

proc bddview_saveas {win} {
  global mainwin

  global BDD
  global ZOOM
  global BDDNAME

  set filename [tk_getSaveFile -title "Save As" -initialfile "$BDDNAME.bddview" -parent $win]
  if {[string length $filename] != 0} {

    #remember last path
    cd [file dirname $filename]

    while {$ZOOM > 16} {
      zoomOut $mainwin 0 0
    }

    while {$ZOOM < 16} {
      zoomIn $mainwin 0 0
    }

    set f [open $filename w]

    set i 0
    set llist [$win find withtag "label && tekst"]
    foreach item $llist {
      set name [string range [lindex [$win gettags $item] 0] 1 end]
      set koord [$win coords $item]
      set x [expr floor([lindex $koord 0]) - 18]
      set y [expr floor([lindex $koord 1]) - 18]
      set t [$win itemcget $item -text]
      puts $f "label $name \"$t\" $x $y"
    }

    set nlist [$win find withtag "node && !label && tekst"]
    foreach item $nlist {
      set name [string range [lindex [$win gettags $item] 0] 1 end]
      set koord [$win coords $item]
      set x [expr floor([lindex $koord 0]) - 18]
      set y [expr floor([lindex $koord 1]) - 18]
      set t [$win itemcget $item -text]
      if {$t == "1"} {
        puts $f "terminal $name 1 $x $y"
      } else {
        puts $f "node $name \"$t\" $x $y"
      }
    }

    foreach item $llist {
      set name [lindex [$win gettags $item] 0]
      set succ [lindex [array get BDD $name] 1]
      if {[lindex $succ 0] == "i"} {set succ [lrange $succ 1 end]}
      set linef [string replace $name 0 0 "f"]
      set linet [string replace $succ 0 0 "t"]
      if {[$win find withtag "$linef && $linet && inverted"] == ""} {
        set inv ""
      } else {
        set inv "i"
      }
      puts $f "connect [string range $name 1 end] [string range $succ 1 end] s$inv"
    }

    foreach item $nlist {
      set name [lindex [$win gettags $item] 0]
      set succ [lindex [array get BDD $name] 1]
      if {[lindex $succ 0] == "i"} {set succ [lrange $succ 1 end]}
      if {[llength $succ] == 1} {
        set then [lindex $succ 0]
        puts $f "connect [string range $name 1 end] [string range $then 1 end] d"
      }
      if {[llength $succ] == 2} {
        set else [lindex $succ 0]
        set then [lindex $succ 1]
        set linef [string replace $name 0 0 "f"]
        set linet [string replace $else 0 0 "t"]
        if {[$win find withtag "$linef && $linet && inverted"] == ""} {
          set inv ""
        } else {
          set inv "i"
        }
        puts $f "connect [string range $name 1 end] [string range $else 1 end] l$inv"
        puts $f "connect [string range $name 1 end] [string range $then 1 end] r"
      }
    }

    close $f

    compass "c" $mainwin
    compass "n" $mainwin
  }

}

proc bddview_print {win} {
  global ZOOM
  global XMAX
  global YMAX
  global BDDNAME

  if {$BDDNAME == ""} return
  set koord [$win bbox all]
  if {$koord == ""} return

  set filename [tk_getSaveFile -title "Print to File (postscript)" -initialfile "$BDDNAME.ps" -parent $win]
  if {[string length $filename] != 0} {

    #remember last path
    cd [file dirname $filename]

    set x1 [lindex $koord 0]
    set y1 [lindex $koord 1]
    set x2 [lindex $koord 2]
    set y2 [lindex $koord 3]

    if {[expr (1.0*($y2-$y1))/($x2-$x1)] > 1.415125082} {

      $win postscript -file $filename -pageanchor nw -pagex 0m -pagey 297.039m -x $x1 -width [expr $x2-$x1] -y $y1 -height [expr $y2-$y1] -pageheight 297.039m

    } else {

      $win postscript -file $filename -pageanchor nw -pagex 0m -pagey 297.039m -x $x1 -width [expr $x2-$x1] -y $y1 -height [expr $y2-$y1] -pagewidth 209.903m

    }

  }
}

# ############################################
# FINAL INITIALIZATION
# ############################################

state pan $mainwin $bb1
puts "OK"

if { $argc != 0 } {

  set filename [lindex $argv 0]

  if {[file exists $filename]} {
    bddview_draw $filename
  } else {
    puts "Warning: $filename does not exists"
  }
}

