3.16.13. Editable Graphics with comdraw/ivtools

Author(s): Secil Ugurel

A very useful tool for scientists (an many other people) is the ability to produce editable graphics. Lush provides this feature through the "comdraw" graphic driver. The editability allows one to manually change colors, add text, change line styles, and do all kinds of other things to Lush graphics generated this way.

Opening a comdraw window is done simply with:

  (comdraw-window 10 10 500 500 "My Comdraw Window")
where the first four parameters are the desired positions and dimensions of the window. Any Lush graphic command executed while such a window is the current window will be drawn in this window and will be instantly editable. The graphics-batch construct has the effect of grouping the objects drawn within its scope. Installing ivtools and comdraw

comdraw is part of the ivtools package, available at http://www.ivtools.org/ivtools/ . You need version 1.0.7 or higher of ivtools. version 1.0.7 of comdraw contains special functions that allows to support all Lush graphics functions. (comdraw-window [[[x y] w h] name])

create a comdraw window. This function pops-up a comdraw window of size w and h at position x and y with name name on the screen. To keep the created comdraw window in the window variable and make it the current window the variable window should be set to the result of comdraw-window , as in:
(setq window (comdraw-window)) Support for Graphics Commands

Almost all the graphics functions of Lush are supported by the comdraw driver. However, some are not supported, or have a different behavior than with the x11 driver.

comdraw Graphics are considerably slower than x11 graphics.

Functions clip and addclip are supported, but due to the lack of an internal clipping function in comdraw, only line clipping is performed in comdraw windows.

graphics-batch groups the object created by the evaluation of the graphics commands within its scope.

The graphics event functions hilite , get-click , get-vector , get-rect and the EventLock objects, read-event and check-event functions are not supported. The imaging functions hinton-map and get-image are not supported. comdraw Specific Functions

Using the gspecial function in Lush, Comdraw-specific commands can be sent directly to the Comdraw interpreter. Below is a list of Comdraw commands (See Comdraw Manual for further information). Be aware that the origin of an original Comdraw window is the bottom left corner. When using standard Lush graphic functions on a comdraw-window, appropriate conversions are performed to set the origin to the upper hand corner. However when gspecial is used directly, no such transformation is performed.
compview=rect(x0,y0,x1,y1) -- creates a rectangle
compview=rectangle(x0,y0,x1,y1) --  creates a rectangle
compview=line(x0,y0,x1,y1) -- creates a line
compview=arrowline(x0,y0,x1,y1) -- creates an arrow line
compview=ellipse(x0,y0,r1,r2) -- creates an ellipse
compview=text(x0,y0 textstr) -- creates a text string on pixel coordinates x0, y0
compview=multiline(x0,y0[,x1,y1,...]) -- creates a multiline 
compview=arrowmultiline(x0,y0[,x1,y1,...]) -- creates an multiline with arrows
compview=openspline(x0,y0[,x1,y1,...]) -- creates an open spline
compview=arrowspline(x0,y0[,x1,y1,...]) -- creates an open spline with arrows
compview=polygon(x0,y0[,x1,y1,...]) -- creates a polygon
compview=closedspline(x0,y0[,x1,y1,...]) -- creates a closed spline
compview=raster(x0,x1,y0,y1) -- creates an empty raster
xylist=center(compview :xy :yx :x :y :scrn) -- returns the center of a compview (default is :xy)
rectlist=mbr(compview :lbrt :lrbt :scrn) -- returns the minimum bounding rectangle of acompview (default is :lbrt)
ptlist=points(compview :scrn) -- returns the point list from a compview graphic
font(fontnum) -- sets the current font from the menu
brush(brushnum) -- sets the current brush from menu
pattern(patternnum) -- sets the current pattern from menu
colors(fgcolornum bgcolornum) -- sets current fore ground and background colors from menu
nfonts() -- returns the size of font menu
nbrushes() -- returns the size of brush menu
npatterns() -- returns the size of pattern menu
ncolors() -- returns the size of color menus
select([compview ...] :all :clear) -- makes the listed graphics the current selection
delete(compview [compview ...]) -- deletes the graphic(s)
move(dx dy) -- moves to the current selection
scale(xflt yflt) -- scales the current selection
rotate(degflt) -- rotates the current selection
newgroup=growgroup(groupview compview) -- adds graphic to an existing group graphic
newgroup=trimgroup(groupview compview) -- removes graphic from an existing group graphic
compview=setattr(compview [:keyword value [:keyword value [...]]]) -- sets attributes of a graphic component
attrlist(compview) -- returns attribute list of a component
compview=frame([index]) -- returns composite component for a frame, defaults to current
val=at(list|attrlist|compview n :set val) -- returns (or set) the nth item in a list.
num=size(list|attrlist|compview) -- returns size of a list.
update() -- updates the viewer
error=save([pathstr]) -- saves the document (to the pathname)       
compview=import(pathstr :popen :next) -- imports graphic file from pathname or URL, or from a command if :popen
(:next imports next in numeric series)
export(compview[,compview[,...compview]] [path] :host host_str :port port_int :socket :string|:str :eps :idraw) 
-- exports a graphic file from pathname or URL, or from a command
compview=paste(compview [xscale yscale xoff yoff | a00,a01,a10,a11,a20,a21]) -- pastes a graphic into the viewer
val=pastemode([val] :get) -- toggles or set paste mode, default is 0, always pastes new graphics
compview=addtool(pathname) -- adds button to toolbar based on zero-centered idraw drawing.
ncols() -- onscreen horizontal extent in pixels
nrows() -- onscreen vertical extent in pixels
dx,dy=stod(sx,sy) -- converts from screen to drawing coordinates
sx,sy=dtos(dx,dy) -- converts from drawing to screen coordinates
dx,dy=gtod(compview gx,gy) -- converts from graphic to drawing coordinates
gx,gy=dtog(compview dx,dy) -- converts from drawing to graphic coordinates
handles(flag) -- enable/disable current selection tic marks and/or highlighting
highlight(compview compviewgs) -- set the highlight graphic state for a graphic
zoom(zoomflt) -- zoom by factor
zoomin() -- zoom-in by 2
zoomout() -- zoom-out by 2
pan(px py) -- pan viewer
smallpanup() -- small pan up
smallpandown() -- small pan down
smallpanleft() -- small pan left
smallpanright() - small pan right
largepanup() -- large pan up
largepandown() -- large pan down
largepanleft() -- large pan left
largepanright() -- large pan right
tilefile(inpath outpath [xsize] [ysiz]) -- tiles pgm or ppm image file
poke(compview x y val) -- pokes pixel value into raster
pcols(compview) -- returns number of columns in a raster
pcols(compview) -- returns number of rows in a raster
pflush(compview) -- flushes pixels poked into a raster
pclip(compview x1,y1,x2,y2,x3,y3[,...,xn,yn]) -- clips raster with polygon
alpha(compview [alphaval]) -- sets/gets alpha transparency
-- requires plotmtv and pstoedit -- 
barplot([var_str value_float] [...] :title title_str :xtitle xtitle_str 
       :ytitle ytitle_str :valtitle valtitle_str :newview) -- displays a barplot
run(filename) -- runs commands from file
quit() -- quits this interpreter
exit() -- exits entire application
pause([msgstr]) -- pauses script execution until C/R Internals

The interaction with the Comdraw process is performed via a pseudo-terminal. Lush commands are converted to Comdraw commands and sent through the terminal. Lush then waits for comdraw to write its answer. This text-based handshake make the whole process a bit slow. Differences in the Patched Version of comdraw

The following commands have been added to comdraw to support certain Lush graphic functions (such as colors and raster images). Those functions are not present in v1.0.6 and earlier of ivtools, but are present in version 1.0.7 (released in November 2002):