Class ::tycho::EditDAG


Inherits: ::tycho::Graphics - Source File - Contents: itk_options - public methods - protected methods - protected variables
A directed acyclic graph (DAG) is a data structure is a set of nodes with any number of parents and children such that no subset of these nodes forms a cycle. This class provides a widget to interactively build, view, and edit such a data structure. The DAG is displayed with root nodes at the top and children below each parent. When the ordering is arbitrary, alphabetical ordering is used. The alphabetical ordering is based on the node name, which may not be the label that is displayed.

This class is meant to serve as a base class for such tools as class browsers for object-oriented languages, precedence graph displays, etc. The EditDAG top-level window class provides a convenient container for this widget.

Data stored on the nodes of the graph are lists in the form {key value key value ... }, where the keys and values are arbitrary Tcl strings. However, certain keywords are recognized to control the display and behavior of the editor. In particular, The following keywords are currently understood:

label
The value field gives the label used to show the node in the display. If this is not present, then the node name is used.
color
The value field gives the color used to show the node in the display. If this is not present, then the node color is black. The color name is processed to make sure it is valid, and if not, black is used.
font
The value field gives the font used to show the node in the display. If this is not present, then the default font given by the defaultFont preference is chosen. The value can take any form understood by the getFont method of the FontManager class.
link
The value field gives a list with two elements, a filename and a fragment within the file, in the standard Tycho hyperlink format. Double clicking on the node will activate the hyperlink. The filename may be absolute or relative, and may begin with an environment variable (such as $TYCHO), or a user directory (~username). If the filename is relative, then the reference directory is that of the file of the top-level editor that contains this EditDAG. The fragment may be a string identifying a named anchor in an HTML file, or "{line linenumber}" or "{range start end}" for text files, or any other destination that is understood by the seeFragment method of the widget that will display the hyperlink.
altlink
This field is the same as link, except that the hyperlink is invoked by shift-double-clicking.
html
The value field gives HTML source code that will be rendered and displayed in a message window in response to a double click on the node. If both this field and the "link" field are given, then both will be activated by a double click.
tcl
The value field gives tcl source code to be evaluated in response to a double click on the node.

Here is an example of the EditDAG:

    ::tycho::view EditDAG

.


Itk_options

-graph
If an non-empty string is given as the value to this argument, it is taken to be the name of an instance of class DirectedAcyclicGraph to display and edit. The instance must exist already and be accessible in the current scope. Note that the name of the graph cannot be the same as any of the methods of this class, or the class gets confused trying to access the graph. In particular, this means that the graph should not be called "graph", a fairly natural name to choose. After configuring this option, you must call redrawGraph for the new graph to be visible.
-layout normal
Specify normal or alternate layout. Must redraw after changing.
-orientation horizontal
Specify vertical or horizontal orientation. Must redraw after changing.
-spacingx 1.0
Default horizontal spacing (as a fraction of a nominal default).
-spacingy 1.0
Default vertical spacing (as a fraction of a nominal default).
-startx 10
Start position in the horizontal direction (in pixels).
-starty 5
Start position in the vertical direction (in pixels).

Public constructs

Public Methods

add name contents {parents {}}
Add a node with the given name, contents, and list of parents. If no parents are specified, then the node is a root node. The graph is not redrawn. Record the addition for undoing.
addArc
Add a new between two currently selected nodes. The first selected node will be the parent, and the second will be the child. If there are not two currently selected nodes, issue a message instructing the user to select a pair of nodes.
addChild
Add a new child node to the currently selected node. If there is no currently selected node, issue a message instructing the user to select a node. Otherwise, query the user for the name and contents. If there is more than one currently selected node, make the new node a child of both.
addRoot
Add a new root node to the graph. Query the user for the name and contents.
clear
Clear the display, discarding the current graph.
copy {ids {}}
Copy the commands to create the specified nodes and all their children to the clipboard. If no items are specified, then copy the selected items and their children. The argument is a list of item ids. If any of the item ids are not nodes, then the base class copy method is used to copy them.
current
Return the name of the current node (the one under the mouse). If there is no current node, return an empty string.
deleteSubgraph name
Delete a node with the given name and all of its children. It is an error if the node does not exist. Record the deletion for undoing. This method is designed to be invoked via the delete method of the base class. The graph is not redrawn after the deletion.
describe
Describe the x and y spacing options plus all options and items described by the base class method.
editNode id
Edit the specified nodes, or if none, the selected nodes. The argument is the id of the canvas item representing the node.
exportImagemap filename {keepfragment 0}
Generate an image map file to go with a GIF image of the canvas. The file generated conforms to the format expected by the NCSA imagemap program that comes with the HTTP server. To use the file in conjunction with a GIF image generated by the exportGif method, put the file in your public web space, such as in ~/public_html/file.map, and reference it in your HTML document as in the following example:
<a href="/cgi-bin/imagemap/~username/file.map">
<img src="file.gif" ismap>
</a>
The hyperlinks apparently must be absolute (i.e. a full URL), although the documentation says that they can be relative to the location of the imagemap file. In either case, note that this may require that you move the files that are the hyperlink destination. You may also need to edit the imagemap file if the hyperlink destination uses special features of Tycho, such as specifying a file name relative to an environment variable. If the optional second argument is given and has value 1 then the fragment information in the hyperlink is preserved. Otherwise, it is discarded. The default is to throw away the fragment information since many Tycho syntaxes for this will be incomprehensible to most Web viewers.
graph
Return the name of the graph object being edited.
help
Open a help window.
modify args
Modify the canvas by executing the arguments in the scope of this object. The command is identified as a distinct action for undo, the window is marked modified (if appropriate), the display is updated, and the focus is returned to this object. If the object is read-only, ring the bell and return, doing nothing. Redraw the graph.
redrawGraph
Redraw the graph. The vertical spacing between nodes is independent of how the nodes are displayed. The horizontal spacing depends on the width of the nodes. The rationale for this is that for textual node displays, it is more appealing to have the vertical spacing be uniform than to have it vary with font changes. This method calls ::tycho::safeUpdate, so that even for large graphs, the system will remain interactive while the graph is being drawn.
reload
Reload the current file. This is redefined in order to redraw the graph. Also, the graph is checked to make sure that all referenced parents and children are present, and that the graph is acyclic. It is repaired if not by deleting the offending references.
setNode oldname newname contents
Set a new name and contents for the specified node. It is an error if the new name is already the name of another node. To change the contents without changing the name of the node, just specify the same name twice.
setReadOnly bool
Specify whether or not modifications are allowed in the displayed text. Note that this is independent of whether the associated file is readonly. It merely determines whether the buffer can be modified, not whether the file can be modified. To control the file, use toggleReadOnly.
setSpacing
Query the user for x and y spacing.
toggleLayout
Toggle between layout algorithms.
transpose
Change layout from horizontal to vertical or vice versa.
verify {repair {}}
Verify that all parents and children of all nodes exist as nodes in the graph and that the graph is acyclic. If no argument is given, or if the argument is an empty string, then trigger an error on the first invalid one encountered. Otherwise, repair the graph by removing the offending reference to a parent or child.

Protected constructs

Protected Methods

configureContextMenu
Configure the popup menu according to context. For the Graphics widget, this method looks to find out if the mouse is over a node, and creates menu entries accordingly.
contentsToArray node arrayname defaults
Given a node name, an array name, and a set of defaults, set entries in the array to the values specified by the defaults, then to the values specified by the contents of the node. That is, the values specified by the contents override values in the defaults. Each of the defaults and the contents must be a list with an even number of elements, {key value key value ...}, where each key is the index used to address the array, and the value is value given to that array entry.
drawNode node xcoord ycoord
Draw a node at the given position. Return a boolean indicating whether the node is "open". This is ignored in this class, but in derived classes, it means that its children should be drawn. As a side effect, set the "bbox" attribute to the bounding box of the node.
drawParentLines node {parent {}}
Draw a line from the specified node to one or all of its parents. It is assumed that the node and each parent have already been drawn with drawNode. If no parent is specified, draw lines to all parents.
preference mode args
Access the preferences associated with this widget. This method overrides the default method in ::tycho::TWidget to access the "diagram" preferences.
showCurrentNodeInfo state {invert 0}
Show information about the current node. The argument must be the state field from a Tk event. If the second argument is supplied and is true, then the shift value of the state field is taken to from before an event that swapped it.
structClass
Return the name of the data structure class being edited.
verifycontents contents
Verify that the argument is a properly formatted list.

Protected Variables

boxcolor
The color of the background box.
defaultfont
The default font name.
linkcolor
The color of hyperlinks.
linecolor
The color of lines.
defaultipath http://ptolemy.eecs.berkeley.edu/
The default http path name for image map files.
mygraph
The name of the graph being edited.
nametable
A table of names, indexed by the id of the text object.

Index of classes



Author: Edward A. Lee
Version: @(#)EditDAG.itcl 1.27 12/14/96
Copyright: (c) 1995-1996 The Regents of the University of California.