processing.dxf
Class RawDXF

java.lang.Object
  extended by processing.core.PImage
      extended by processing.core.PGraphics
          extended by processing.core.PGraphics3D
              extended by processing.dxf.RawDXF
All Implemented Interfaces:
java.lang.Cloneable, PConstants

public class RawDXF
extends PGraphics3D

A simple library to write DXF files with Processing. Because this is used with beginRaw() and endRaw(), only individual triangles and (discontinuous) line segments will be written to the file.

Use something like a keyPressed() in PApplet to trigger it, to avoid writing a bazillion .dxf files.

Usually, the file will be saved to the sketch's folder. Use Sketch → Show Sketch Folder to see it from the PDE.

A simple example of how to use:

 import processing.dxf.*;

 boolean record;

 void setup() {
   size(500, 500, P3D);
 }

 void keyPressed() {
   // use a key press so that it doesn't make a million files
   if (key == 'r') record = true;
 }

 void draw() {
   if (record) {
     beginRaw(DXF, "output.dxf");
   }

   // do all your drawing here

   if (record) {
     endRaw();
     record = false;
   }
 }
 
or to use it and be able to control the current layer:
 import processing.dxf.*;

 boolean record;
 RawDXF dxf;

 void setup() {
   size(500, 500, P3D);
 }

 void keyPressed() {
   // use a key press so that it doesn't make a million files
   if (key == 'r') record = true;
 }

 void draw() {
   if (record) {
     dxf = (RawDXF) createGraphics(width, height, DXF, "output.dxf");
     beginRaw(dxf);
   }

   // do all your drawing here, and to set the layer, call:
   // if (record) {
   //   dxf.setLayer(num);
   // }
   // where 'num' is an integer.
   // the default is zero, or you can set it to whatever.

   if (record) {
     endRaw();
     record = false;
     dxf = null;
   }
 }
 
Note that even though this class is a subclass of PGraphics, it only implements the parts of the API that are necessary for beginRaw/endRaw.

Based on the original DXF writer from Simon Greenwold, February 2004. Updated for Processing 0070 by Ben Fry in September 2004, and again for Processing beta in April 2005. Rewritten to support beginRaw/endRaw by Ben Fry in February 2006. Updated again for inclusion as a core library in March 2006. Constructor modifications in September 2008 as we approach 1.0.


Field Summary
 
Fields inherited from class processing.core.PGraphics3D
camera, cameraAspect, cameraFar, cameraFOV, cameraNear, cameraX, cameraY, cameraZ, currentLightFalloffConstant, currentLightFalloffLinear, currentLightFalloffQuadratic, currentLightSpecular, lightCount, lightDiffuse, lightFalloffConstant, lightFalloffLinear, lightFalloffQuadratic, lightNormal, lightPosition, lightSpecular, lightSpotAngle, lightSpotAngleCos, lightSpotConcentration, lightType, line, MAX_LIGHTS, modelview, modelviewInv, projection, smoothTriangle, TRI_COLOR_COUNT, TRI_DIFFUSE_A, TRI_DIFFUSE_B, TRI_DIFFUSE_G, TRI_DIFFUSE_R, TRI_SPECULAR_B, TRI_SPECULAR_G, TRI_SPECULAR_R, triangle, zbuffer
 
Fields inherited from class processing.core.PGraphics
ambientB, ambientG, ambientR, backgroundColor, bezierDetail, colorMode, colorModeA, colorModeX, colorModeY, colorModeZ, curveTightness, edge, ellipseMode, emissiveB, emissiveG, emissiveR, fill, fillColor, image, imageMode, normalX, normalY, normalZ, pixelCount, rectMode, shapeMode, shininess, smooth, specularB, specularG, specularR, sphereDetailU, sphereDetailV, stroke, strokeCap, strokeColor, strokeJoin, strokeWeight, textAlign, textAlignY, textFont, textLeading, textMode, textSize, textureImage, textureMode, textureU, textureV, tint, tintColor
 
Fields inherited from class processing.core.PImage
format, height, parent, pixels, width
 
Fields inherited from interface processing.core.PConstants
A, AB, ADD, AG, ALPHA, ALPHA_MASK, ALT, AMBIENT, AR, ARC, ARGB, ARROW, B, BACKSPACE, BASELINE, BEEN_LIT, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CENTER_DIAMETER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DA, DARKEST, DB, DEG_TO_RAD, DELETE, DG, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_OPENGL_2X_SMOOTH, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DR, DXF, EB, EDGE, EG, ELLIPSE, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ER, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, G, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMAL, NORMALIZED, NX, NY, NZ, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, R, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SA, SB, SCREEN, SG, SHAPE, SHIFT, SHINE, SOFT_LIGHT, SPB, SPG, SPHERE, SPOT, SPR, SQUARE, SR, SUBTRACT, SW, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, TX, TY, TZ, U, UP, V, VERTEX_FIELD_COUNT, VW, VX, VY, VZ, WAIT, WHITESPACE, WINDOWS, X, Y, Z
 
Constructor Summary
RawDXF()
           
 
Method Summary
 void beginDraw()
          Prepares the PGraphics for drawing.
 void beginShape(int kind)
          Start a new shape.
 boolean displayable()
          Return true if this renderer should be drawn to the screen.
 void dispose()
          Handle any takedown for this graphics context.
 void endDraw()
          See notes in PGraphics.
 void endShape(int mode)
           
 void println(java.lang.String what)
          Write a line to the dxf file.
 void setLayer(int layer)
          Set the current layer being used in the DXF file.
 void setPath(java.lang.String path)
           
 void vertex(float x, float y)
           
 void vertex(float x, float y, float z)
           
 void write(java.lang.String cmd, float val)
          Write a command on one line (as a String), then start a new line and write out a formatted float.
 
Methods inherited from class processing.core.PGraphics3D
ambientLight, ambientLight, applyMatrix, applyMatrix, applyMatrix, applyMatrix, beginCamera, box, camera, camera, directionalLight, endCamera, flush, frustum, getMatrix, getMatrix, hint, is2D, is3D, lightFalloff, lights, lightSpecular, modelX, modelY, modelZ, noLights, noSmooth, ortho, ortho, perspective, perspective, pointLight, popMatrix, printCamera, printMatrix, printProjection, pushMatrix, resetMatrix, rotate, rotate, rotateX, rotateY, rotateZ, scale, scale, scale, screenX, screenX, screenY, screenY, screenZ, setMatrix, setMatrix, setSize, smooth, sphere, spotLight, strokeCap, strokeJoin, texture, translate, translate, vertex
 
Methods inherited from class processing.core.PGraphics
alpha, ambient, ambient, ambient, applyMatrix, arc, background, background, background, background, background, background, background, beginRaw, beginShape, bezier, bezier, bezierDetail, bezierPoint, bezierTangent, bezierVertex, bezierVertex, blue, box, breakShape, brightness, canDraw, color, color, color, color, color, color, color, color, color, colorMode, colorMode, colorMode, colorMode, curve, curve, curveDetail, curvePoint, curveTangent, curveTightness, curveVertex, curveVertex, edge, ellipse, ellipseMode, emissive, emissive, emissive, endRaw, endShape, fill, fill, fill, fill, fill, fill, getMatrix, getStyle, getStyle, green, hue, image, image, image, imageMode, lerpColor, lerpColor, line, line, noFill, normal, noStroke, noTint, point, point, popStyle, pushStyle, quad, rect, rectMode, red, saturation, setMatrix, setParent, setPrimary, shape, shape, shape, shapeMode, shininess, showException, showWarning, specular, specular, specular, sphereDetail, sphereDetail, stroke, stroke, stroke, stroke, stroke, stroke, strokeWeight, style, text, text, text, text, text, text, text, text, text, text, text, text, text, text, textAlign, textAlign, textAscent, textDescent, textFont, textFont, textLeading, textMode, textSize, textureMode, textWidth, textWidth, tint, tint, tint, tint, tint, tint, triangle, vertex, vertex
 
Methods inherited from class processing.core.PImage
blend, blend, blendColor, clone, copy, copy, filter, filter, get, get, get, getCache, getImage, init, isModified, loadPixels, mask, mask, removeCache, resize, save, set, set, setCache, setModified, setModified, updatePixels, updatePixels
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RawDXF

public RawDXF()
Method Detail

setPath

public void setPath(java.lang.String path)
Overrides:
setPath in class PGraphics

dispose

public void dispose()
Description copied from class: PGraphics
Handle any takedown for this graphics context.

This is called when a sketch is shut down and this renderer was specified using the size() command, or inside endRecord() and endRaw(), in order to shut things off.

Overrides:
dispose in class PGraphics

displayable

public boolean displayable()
Description copied from class: PGraphics
Return true if this renderer should be drawn to the screen. Defaults to returning true, since nearly all renderers are on-screen beasts. But can be overridden for subclasses like PDF so that a window doesn't open up.

A better name? showFrame, displayable, isVisible, visible, shouldDisplay, what to call this?

Overrides:
displayable in class PGraphics

beginDraw

public void beginDraw()
Description copied from class: PGraphics
Prepares the PGraphics for drawing.

When creating your own PGraphics, you should call this before drawing anything.

Overrides:
beginDraw in class PGraphics3D

endDraw

public void endDraw()
Description copied from class: PGraphics3D
See notes in PGraphics. If z-sorting has been turned on, then the triangles will all be quicksorted here (to make alpha work more properly) and then blit to the screen.

Overrides:
endDraw in class PGraphics3D

setLayer

public void setLayer(int layer)
Set the current layer being used in the DXF file. The default is zero.


write

public void write(java.lang.String cmd,
                  float val)
Write a command on one line (as a String), then start a new line and write out a formatted float. Available for anyone who wants to insert additional commands into the DXF stream.


println

public void println(java.lang.String what)
Write a line to the dxf file. Available for anyone who wants to insert additional commands into the DXF stream.


beginShape

public void beginShape(int kind)
Description copied from class: PGraphics
Start a new shape.

Differences between beginShape() and line() and point() methods.

beginShape() is intended to be more flexible at the expense of being a little more complicated to use. it handles more complicated shapes that can consist of many connected lines (so you get joins) or lines mixed with curves.

The line() and point() command are for the far more common cases (particularly for our audience) that simply need to draw a line or a point on the screen.

From the code side of things, line() may or may not call beginShape() to do the drawing. In the beta code, they do, but in the alpha code, they did not. they might be implemented one way or the other depending on tradeoffs of runtime efficiency vs. implementation efficiency &mdash meaning the speed that things run at vs. the speed it takes me to write the code and maintain it. for beta, the latter is most important so that's how things are implemented.

Overrides:
beginShape in class PGraphics3D

vertex

public void vertex(float x,
                   float y)
Overrides:
vertex in class PGraphics3D

vertex

public void vertex(float x,
                   float y,
                   float z)
Overrides:
vertex in class PGraphics

endShape

public void endShape(int mode)
Overrides:
endShape in class PGraphics3D