[Home]XCircuit/Help

OpenCircuitWiki | XCircuit | RecentChanges | Preferences | Sandbox
Open Circuit Design | Magic | XCircuit | IRSIM | Netgen | PCB

Tips and Ideas

1. Printing and converting schematics
1.1. embedding in LaTeX documents
1.2. converting to GIF or JPEG (useful for embedding in OpenOffice or Word)
1.3. converting to PDF
1.4. Saving to SVG file
2. Cutting and pasting text
3. Useful expression parameters
4. XCircuit Configuration
4.1. Startup script (.xcircuitrc) tips
5. Quick scripting
5.1. Creating info labels from selected labels.
5.2. Creating info labels for pwl input drivers
5.3. Drawing mathematical curves

1. Printing and converting schematics

Of course, XCircuit output is PostScript and is therefore ideally suited to sending directly to a printer. Nevertheless, PostScript is not always the preferred choice for printing. Here are some other options:

1.1. embedding in LaTeX documents

Encapsulated PostScript can be inserted directly into a LaTeX document with the "epsfig" package. LaTeX purists, however, usually like to have continuity between the text of the document and the figure. For that, there is "LaTeX mode" in XCircuit. When this mode is enabled, several things happen: 1) labels created when in LaTeX mode will be marked and processed separately from the figure. 2) when entering text, the backslash key does not generate the special characters display, but just prints a backslash (since backslashes are used often in LaTeX and special characters are declared with backslash commands), and 3) when writing the PostScript output, XCircuit additionally creates a ".tex" file that contains all of the labels in LaTeX format, and a call to "epsfig" to include the image.

1.2. converting to GIF or JPEG (useful for embedding in OpenOffice or Word)

ImageMagick is the best way to handle this, as it automatically deals with antialiasing, etc. The Gimp is another method that gives separate control over text and graphics antialiasing. Usually I choose strong antialiasing on text and weak antialiasing on graphics. With ImageMagick, I use the following for printed documents (a finer resolution may be helpful but probably doesn't buy you much):
convert -density 150x150 -units <file>.ps <file>.gif

1.3. converting to PDF

The tool ps2pdf is the common way to get xcircuit output into PDF. Note that the default is to convert to letter size (8.5 by 11 inches), so xcircuit schematics that have been drawn in other sizes (folio, for example, or A4, or legal) will get clipped unless you use the following option, e.g.:
ps2pdf -sPAPERSIZE=folio <file>.ps
The "import graphic image" in XCircuit uses some arcane PostScript capabilities that allow a stream data image to be stored for subsequent re-use. Unfortunately, I've seen many printers stymied by this (or maybe it's just an error in my ascii-85 encoding subroutine). When this happens, it can be circumvented by using ps2pdf to convert to PDF format. PDF doesn't allow the use of the "reusable stream", and so it converts each use into a separate stream. If you have used many copies of a single graphic, you will end up with a PDF file that is rather larger than the original PostScript, but it is guaranteed to print successfully. If your printer doesn't accept PDF directly, then print from a PDF viewer such as acroread.

1.4. Saving to SVG file

Since version 3.6.161 the Tcl version of xcircuit has SVG export capabilities. Open the Tcl console and type "svg" and an SVG file with the name of the current page will be created. This SVG file can be imported into Microsoft Visio for further embedding in Microsoft Word. Word does not currently understand SVG directly, but an OLE Visio object will. Inkscape also open the SVG file, and the Gtk Text widget will also import the SVG.

xcircuit 3.7 has a menu item File->Export->Export SVG

2. Cutting and pasting text

You can paste text from any program that supports cut-and-paste operations. The script to do this is hidden in the library files. To activate it, bring up the console and type:
source $XCIRCUIT_LIB_DIR/selection.tcl
This simple script changes the function of the middle mouse button in text edit mode. Normally, both the left and middle mouse buttons will terminate text editing. When the text paste function is enabled by the above command, then the middle mouse button will paste text from the cut buffer. This will work with any program that uses the standard cut buffer method, such as an xterm, firefox, acroread, etc. The command line above can be placed in the .xcircuitrc startup file to make it active on every session.

3. Useful expression parameters

Parameters that are Tcl/Tk expressions can do anything the interpreter can do. You can create an expression parameter from the parameter popup window (use Control-P to get the window) by clicking on the menubutton "New..." followed by selecting the menu entry "Expression". Type a unique keyword for the parameter name, then type the Tcl/Tk expression in the "value" box. Here are some useful expression parameters you might like to try:

  1. page links independent
    Print the total number of pages in the file
  2. page links sheet
    Print the current page number
  3. clock format [clock seconds]
    Print the current time
  4. clock format [file mtime [page filename]]
    Print the last file modification time

4. XCircuit Configuration

The built-in way of configuring XCircuit is pretty hard-coded:
  1. ./.xcircuitrc-<major>.<minor>
  2. $HOME/.xcircuitrc-<major>.<minor>
  3. ./.xcircuitrc
  4. $HOME/.xcircuitrc
The first file found is read and the rest is ignored.

I find two problems with this:

  1. Dot files in sub-directories are normally invisible and one tend to "forget" that they are there.
  2. Global settings with local overrides are not possible.

Luckily, there is a way to work around this in the Tcl version of XCircuit:

In the file $HOME/.xcircuitrc place all the global settings towards the top of the file, then at the end of the file place the following command:
 catch {source xcircuit.cfg}
In any work directory create the file xcircuit.cfg and place whatever local config override here.
XCircuit evaluated the .xcircuitrc file as a tcl script, and thus read the file xcircuit.cfg from the current directory. The catch is to avoid error if the file does not exist.

Because .xcircuitrc is evaluated as a Tcl script, this opens a lot of possibilities to place different settings all over your file system. Very powerful and very flexible, but use with care as it is possible to have circular references.

I guess a thorough explanation of the startup files is warranted. XCircuit goes through a rather complicated startup sequence, the purpose of which is to allow a local script to override the system-wide script, but avoiding serious problems that would arise if there were, for example, no colors available, or no fonts. The system startup file is called "xcstartup.tcl". Of course, this gets overwritten whenever xcircuit is updated and re-installed. It would be (more or less) trivial to have a call to a site-wide configuration file that would not be overwritten. I am also amenable to a solution that would read both a user's configuration file and a local (project) configuration file. Currently, I have the system startup file doing nothing more than setting default fonts and libraries. It looks for two Tcl variables called $XCOps(liboverride) and $XCOps(fontoverride) which, if set in the local or user's home startup file, will cause each of these sections to be ignored. However, if the font section is overridden but no fonts are declared, there is a final hard-coded configuration that will define a single font that can be used to display text and symbol names in XCircuit.

From version 3.6.44, XCircuit's startup file xcstartup.tcl tries to execute a file called site.tcl in the same directory (nominally, /usr/local/lib/xcircuit-3.6). If found, it will be executed in place of the contents of xcstartup.tcl. If not, xcstartup.tcl will be sourced as usual. The file site.tcl will never be overwritten or otherwise altered by the XCircuit install process, so you can keep your local definitions safe from updates.

4.1. Startup script (.xcircuitrc) tips

  1. Set a different font
    loadfont Times-Roman
    label family Times-Roman
    label scale 0.7
    
    Note that the startup script is executed before fonts are loaded, so to set a specific font, you have to first load it.
  2. Change the window size
    wm geometry .xcircuit 1550x1150+5+20
    
    This is pure Tk syntax---see the Tk manual page on "wm" for an explanation.
  3. Swap the key binding for "Zoom"
    xcircuit::keybind z { pan here ; zoom in }
    xcircuit::keybind Z { pan here ; zoom out }
    
    This also demonstrates how to get the zoom function to simultaneously center the screen on the cursor position.
  4. Use the right mouse button to raise the parameter window
    bind .xcircuit.mainframe.mainarea.drawing <ButtonPress-3> {
       if {[eventmode] == "normal" && [select get] == {} && [select here] != {}} {
          xcircuit::prompteditparams {substring numeric expression}
       } else {
          standardaction %b down %s
       }
    }
    
    This demonstrates how to override xcircuit's button bindings. XCircuit treats keys and buttons the same (I don't know why other tools don't do that), and all functions can be rebound to either internal pre-defined actions, or to Tcl/Tk scripts.

5. Quick scripting

The tcl nature of xcircuit make it suitable to use quick-and-dirty scripting to solve problems.

5.1. Creating info labels from selected labels.

A typical use is to create spice-N: labels for simulator directives. I use this very often to tell which signals should be plotted.

This script is very Q-A-D and generate a single info label at the origin.

Usage:
save to file autogen_output.tcl in the working directory
In xcircuit select all the info labels that should be included
Bring up the tcl console (or use "execute script" from the file menu)
% source autogen_output.tcl

 set pinlist [xcircuit::element selected text]
 set outstr "spice-1:.output "
 foreach net_name $pinlist {
        append outstr "v($net_name) "
 }
 xcircuit::element deselect ;# label make info does not like selected items
 xcircuit::label make info $outstr [list 0 0]

Now the generated label can be moved to a more propriate place and the spice-N number can be modified appropriately.

5.2. Creating info labels for pwl input drivers

While we're at it with automatic label generating, when looking at tutorial 3, the input pins are driven by pwl sources. Wouldn't it be nice to have these info labels somhow in the vincinity of the pin it is supposed to drive? Here is a little Q-A-D script for that:

Usage:
save to file autogen_input.tcl in the working directory
In xcircuit select all the info labels that should be driven this way
Bring up the tcl console (or use "execute script" from the file menu)
% source autogen_output.tcl

 # autogen_input.tcl
 set mypinlist [xcircuit::element selected text]
 set myposlist [xcircuit::element selected position]

 xcircuit::element deselect ;# label make info does not like selected items

 for {set mycount 0} {$mycount < [llength $mypinlist]} {incr mycount} {
        set net_name [lindex $mypinlist $mycount]
        foreach {x0 y0} [lindex $myposlist $mycount] break
        xcircuit::label make info "spice-$mycount:v_$net_name $net_name 0 PWL (0 0)" [list $x0 $y0]
 }

This script take the effort to extract the location of the pin labels the sources are supposed to drive. Some postprocessing like make the text left or right aligned, increment or decrement the spice-N numbers may be needed.

And you will have to fill in the pwl patterns, of course.

5.3. Drawing mathematical curves

Sometimes you want to generate a curve from a given equation. There are software that can do this, such as MATLAB and Gnuplot. What these other softwares lack is the ability to interactively edit and add to the resulting graph. With the Tcl interface of XCircuit, this becomes possible: One can generate the curve first using Tcl, and then use the curve in XCircuit.

The following is one example that generate a Lissajou curve:

# Plot a Lissajou Pattern in Xcircuit

# constants
set xscale 144
set yscale 144
set pi 3.1415926

# curve parameters
set m 4
set n 3
set c .3*$pi

# generate the curve
set t 0
set list ""
set N 0

while { $t <= 1 } {
	set x [expr sin(2*$pi*$m*$t+$c)]
	set y [expr sin(2*$pi*$n*$t)]

	set xx [expr int($x * $xscale)]
	set yy [expr int($y * $yscale)]

	set list [concat $list \{$xx $yy\}]

	set N [expr $N + 1]
	set t [expr $t + .005]
}

# plot it
eval polygon make $N $list

The above Tcl commands can be put in a file (say lissajou.tcl) and run in the Tcl console using source lissajou.tcl. Note that one needs to click the main XCircuit window once after running the script to see the generated graph. The script can be improved if spline curves are used as segments of the curve (the whole curve in that case needs to be an object as opposed to a polygon).


OpenCircuitWiki | XCircuit | RecentChanges | Preferences | Sandbox
Open Circuit Design | Magic | XCircuit | IRSIM | Netgen | PCB
Page is read-only (use admin password ocd_edit to make writeable) | View other revisions
Last edited August 31, 2010 2:54 pm by SvennBjerkem (diff)
Search: