← Back to team overview

kicad-developers team mailing list archive

Revised batch plot control file

 

I revised my ideas on the batch plot facility after some experimentation (the testbed was useful). Here is a 'converted' control file showing all that it can do at the moment.

All the features are in there, only the parser/executor has to be implemented.

My 'biggest' problem on the dsnlexer for now was that the comment character is # instead of ; (and it choked on my lisp commenting habits:P:P)

-- 
Lorenzo Marcantonio
Logos Srl
# pcbnew batch control file
# Comment lines and blank lines are ignored (uses the dsnlexer)
# NOTE these are like sexp *but* the comment character is # not ;

# Some options are 'for file' and are took in account mostly when the plot is 
# started; other ones are processed for each layer. There are 3 nesting level
# for setting options: job level, output (file) level and layer level
#
# Options from the outer levels become defaults from the inner ones (unless 
# overridden), settings in the inner levels are 'lost' when returning to the
# outer one. It's easier done that explained. If you've ever configured
# apache httpd the system is mostly the same for directories and/or virtual 
# hosts...
#
# This should be flexible enough to be extended in future to drive other
# fabrication reporters

# The outer element, contains default definitions for *everything* and
# output elements
(batchplot 
    # These are default for *everything* inside. At the moment the only
    # thing that come preset is the output directory (from the plot dialog),
    # everything else is from hardcoded defaults. Maybe some other general
    # option could be usefully taken for defaulting (like the fine scale
    # adjust and the default linewidth which are *not* from the board IIRC)

    # Anyway lets establish some 'sane' default options
    (autoscale false)
    (scale 1.0)
    (mirror false)

    # Default linewidth is in BIU 
    # (a unit-generic parser like the one in the dialog boxes could be useful)
    (linewidth 200000)

    # These are postscript options only, and even then rarely used (I hope so)
    (psa4output false)
    (psnegative false)
    (finescaleadjustx 1)
    (finescaleadjusty 1)
    (finewidthadjust 0)

    # HPGL options should really go in the layer ones but currently
    # they are only set on plotter opening (it would need additions to the
    # core plotter classes); maybe I'll fix that later. So these are actually
    # output-level options (defaulted here). Note that, for some reason,
    # HPGL pen size and overlay are specified in mils and pen speed in cm/s
    (hpglpennumber 1)
    (hpglpenspeed 10)
    (hpglpendiameter 7)
    (hpglpenoverlay 0)

    # Now we can open an output file i.e. and output element. 
    # The name specified is stemmed to the board name
    # and the current output directory is taken in account. 
    # The extension is optional and if specified overrides the default one.
    # In this way we can create a plot control file independant by the board and
    # use it for all the similar ones

    # Here I could override the plot dialog output directory
    #(outputdirectory "fabs")

    # Premise: the idea is to have a declarative view of the option settings
    # i.e. independant of the order. However the parser doesn't work this way,
    # is more an imperative state machine... in fact you could change job 
    # options between output elements and it would work in the 'obvious' way 
    # (i.e. changing defaults for the successive plots). I think that's not a
    # good way to organise this file, it would be way to easy to forget a state
    # change for an option (it happened a lot with the previous incarnation).
    # We could consider to forbid option setting after the first subelement:
    # in this way job option would be 'frozen' for each output (and each output
    # option would be similarily frozen for each of its layers)
    #
    # OTOH it would be easier to set stuff like 'from there on I want this
    # output directory until I change idea', so at the end maybe is best to
    # let the user shoot in his own foot if he wants
 
    # Let's start a somewhat convoluted example: I use a really cool mill
    # driven by HPGL, so I want the pcb edge done. Here I override the default
    # .plt extension, too.

    # Other useful defaults

    # Drill shape (not used for gerber plots) 0=NO 1=SMALL 2=FULL
    # 'small' would give small marks and true hole-sized marks
    (drillshape false)

    (viasonmask false)
    (plotmode fill)
    
    # I don't want frame references by default, otherwise I'd have to disable
    # them (for example) for each gerber. Is easier to enable them for the
    # plot I want them on... obviously a GUI generator could simply set *every*
    # option every time without issues...
    (plotframeref false)

    # excludeedgelayer to false is a convenience; you could have (almost) the 
    # same result plotting separately the edge layer before switching plotfile
    (excludeedgelayer true)

    # Sane defaults for silk plots
    (plotreference true)
    (plotvalue true)
    (plotothertext true)
    (plotinvisibletext false)

    # Please note: the padsonsilk *enables* pads on the silk layer, but the
    # the pads should be on the silk to be plotted (i.e. it doesn't force them)
    # With the multilayer plot feature this option become (almost?) obsolete,
    # like the excludeedgelayer one
    (padsonsilk false)

    # These will be used only by gerbers
    (useauxorigin true)
    (subtractmaskfromsilk true)

    # Open an output element: it inherits all the job options. There are two
    # things you *absolutely* need to set: the format (i.e. file type) and
    # the file stem (i.e. the variable part of the filename)
    (output
	(outputformat hpgl)
	(stem "EdgeMill.hpgl")

	# Maybe I also want this file in a different subdirectory (it *replaces* 
	# the dialog one; don't ask too much, now...)
	(outputdir "fabs/mill")

	# Important thing to know: the plot file is not open until the first
	# layer element (so you have time to set output-level options) and
	# it's closed when the output element is closed.

	# It's a mill, so use line mode (other choices are fill and sketch)
	(plotmode line)

	# Opening the first layer element open the plot file
	(layer
	    # In the layer element the only required attribute is the
	    # layer number (it's numeric since the layer name is not set
	    # in stone); other layer-level option could be set here, of 
	    # course. Since this is a single layer plot it doesn't matter:
	    # I could have put the plotmode option here with the same
	    # result.
	    (layer 28))) 
	# The layer is plotted at the closing of the layer element, then 
	# the output file is closed too and we're back to job level.
	# On to the next plot...


    # I want to do a postscript plot for toner transfer (it's a single side)
    # Small drill mark, mirror image. The mirror option has to be set *before*
    # opening the file, since is output-level
    (output
	(outputformat ps)
	(stem "TonerTransfer")

	# Here I set the mirror option, valid for this output and its layer
	# the job level option is not touched so the next output would start
	# with a (mirror false) default. The same for the drillshape option
	(mirror true)
	(plotmode fill)
	(drillshape small)

	# Open the output and do the copper layer
	(layer
	    (layernum 0)))

    # Now to finish it up a silk pdf to help me assemble the board
    (output
	# Make it big, so I can read it better...
	(autoscale true)
	# Here I set stem and format after other options, it doesn't really
	# matter until I open a layer entity (see the comment above about
	# 'freezing' options)
	(outputformat pdf)
	(stem "Silk")
	(layer
	    (layernum 21)))

# From now on I got rich and decided to do a more 'conventional' fabrication

    # Lets start with a conventional set of gerbers
    # These are pretty trivial, I don't even feel to write them on multiple
    # lines (since I've all the defaults right from the job level)
    (output (outputformat gerber) (stem "Copper") (layer (layernum 0)))
    (output (outputformat gerber) (stem "Mask") (layer (layernum 22)))
    (output (outputformat gerber) (stem "Silk") (layer (layernum 21)))
    (output (outputformat gerber) (stem "Edges") (layer (layernum 28)))
    (output (outputformat gerber) (stem "Drawings") (layer (layernum 24)))

    # Our fabricators want two additional gerbers:
    # An assembly with no silk trim and all and only the references
    # (you'll see that even holes have designators, obviously)
    (output
	(outputformat gerber)
	(stem "Assy")
	(subtractmaskfromsilk false)
	(plotvalue false)
	(plotothertext false)
	(plotinvisibletext true)
	(layer (layernum 21)))
 
    # And a gerber with only the component outlines (really!)
    (output
	(outputformat gerber)
	(stem "AssyOutlines")
	(plotreference false)
	(plotvalue false)
	(plotothertext false)
	(layer (layernum 21)))

    # Everything until now could be done from the standard plot dialog
    # (in many steps, of course); now we do plots with more than one layer
    # in them (multilayer plots)

    # For documentation we also want a general layout PDF
    # I usually use a shell script to merge the ps files and then distill 
    # the result
    (output
	(stem "Layout")
	(outputformat pdf)
	(plotframeref true)
	# Just for kicks, use the native PDF helvetica font instead of the
	# builtin vector font (results may vary... with the default 'phantom'
	# text the result is still searchable while using the internal stroke
	# font). Valid values for textmode are: 
	# stroke: only vector text, no search capability (every format)
	# native: use format native font, full search capability but layout
	#         may suffer (supported by PS, PDF and DXF)
	# phantom: use vector font and an 'hidden' text to support search
	#          (supported by PDF and, with some limitation, by PS)
	(textmode native)

	# Start with the drawings (could be put at the end, depending on 
	# preferences... layer order *does* matter!)
	(layer (layernum 24))

	# Each layer can be plotted in a different colour. This is useful. 
	# Do the PCB edges in yellow - here is our first layer level option
	(layer 
	    (layernum 28)
	    (plotcolor 14))

	# Solder mask as lines only, in red
	(layer (plotmode line) (plotcolor 4) (layernum 22))
	# Silk in blue
	(layer (plotcolor 1) (layernum 21)))
	# A more complex board obviously would have more layers and paste and so on...
 
    # To finish up, we have to please the MCAD people 
    # I say it's almost a cut and paste job...
    (output
	(stem "Assy")
	(outputformat dxf)
	(plotframeref true)
	# Due to the kind of geometry used in DXF it's better to use line mode
	# for most layers. Copper is an exception for obvious reasons, unless
	# for some reason you're only interested in track topology...
	# (see below)
	(plotmode line)
	(layer (layernum 24))
	(layer (layernum 28) (plotcolor 14))
	(layer (plotcolor 4) (layernum 22))
	# Yet Another Useful Feature with layers: silk layers can use different
	# colors for reference and value. Since the DXF driver maps color to
	# layer we'll have references and values on different layers. Forcing
	# invisible text on allows to have the full text on the board available
	# simply turning on/off layers on the cad program. *Very* useful for
	# repairs diagrams.
	(layer 
	    (plotcolor 1) 
	    (layernum 21)
	    (plotinvisibletext true)
	    (referencecolor 5)
	    (valuecolor 6))

	# Another useful feature: drill marks on copper layers are exported as
	# 'whiteout' circles; the DXF version we use doesn't handle whiteouts
	# but the net results is that plotting *any* copper layer in fill mode
	# with drill marks gives you the drill marks in the WHITE layer
	# I admit is kind of an hack but it works until we get a better drill 
	# plot (the drill reference diagram has its own issues)
	(layer
	    (plotcolor 7)
	    (plotmode fill)
	    # Full drill marks are great to snap and stuff in the cad
	    (drillshape true)
	    (layernum 0))))


Follow ups