PICTools Programmer's Reference
OP_CAD2D

OP_CAD2D: Convert a CAD Drawing File to a DIB

The purpose of OP_CAD2D (see opcode specific data structure) is to convert CAD drawing files to DIBs. This opcode supports conversion of the following types of files:

The overall processing flow for this opcode is as follows:

  1. The client application allocates a Get Queue buffer.  This buffer can be either large enough to contain the entire input file or a portion of the file, in which case, the opcode will support streaming input.  For streaming input, the opcode will internally buffer the file contents until the entire file has been received by the opcode.  The client signals to the opcode that the entire file has been read by setting Q_EOF in Get.Qflags.   
  2. The client application invokes REQ_INIT processing.  The opcode parses the contents of the Get Queue into internal data structures, allocates and populates the Layouts and Layers arrays, sets the NumLayouts, NumLayers, Units, RenderBitDepth, BackgroundColor, and LayoutToRender fields to initial values and returns RES_DONE to the client. The client may now deallocate the Get Queue buffer.
  3. The client application determines which layout to render and sets the LayoutToRender field (or leaves it set to the default value, which is the active layout).  The client sets the RenderWidth, RenderHeight, and optionally, the RenderBitDepth, BackgroundColor and Layers[n].Off fields, for n from 0 to NumLayers-1.
    Since, in this step, the client is telling the opcode which layout to render and the output dimensions,  the opcode has not yet returned to the client the required StripSize.  Therefore, the client doesn't know the minimum required size of the Put Queue and may not be able to allocate the correct size Put Queue at this time.  In this case, the client should make sure Put.Start is set to 0.
  4. The client application invokes REQ_EXEC processing. The opcode sets StripSize and returns with RES_PUT_NEED_SPACE to the client.
  5. At this point, the client can allocate space for the Put Queue.  Streaming output is supported, so either enough space for the entire output image can be allocated, or partial space (with a minimum of StripSize) can be allocated.
  6. The opcode returns image data until the complete specified layout has been rendered.

This opcode supports multiple, successive REQ_EXEC operations, without intervening REQ_TERM or REQ_INIT operations. This is useful for multiple renderings of the same image, for example, if zooming or panning around the image.  Executing multiple REQ_EXEC operations is more efficient in that it eliminates the need to perform the REQ_INIT processing.  Of course, if a different CAD file is to be processing, then REQ_INIT must be executed for the new file.

Output DIB

A CAD drawing file can contain multiple layouts, however, only a single layout can be rendered to a DIB at one time.  The LayoutToRender field is used to select the desired layout.  It defaults to the active layout.  The active layout is the layout that was last active in the CAD application when the drawing file was saved.  To render the Model Space layout, the LayoutToRender field may be set to the value RENDER_MODEL_SPACE.

A CAD drawing file can also contain multiple layers.  The drawing layers are specified in the Layers array element field.  To exclude a layer from the rendered bitmap, set the Layer[n].Off field to TRUE.  Multiple layers may be excluded from the output.  Also, if layers turned off in the input file, these layers can be included in the output bitmap by setting the Layer[n].Off field to FALSE.

The dimensions of the output DIB are specified by setting RenderWidth and RenderHeight. These fields must be set by the client application.

The bit depth of the output DIB can be specified by setting RenderBitDepth. The default is 8bpp.  Allowable values are 1, 4, 8, 24, and 32 bpp.

The background color of the output DIB can be specified by setting BackgroundColor. This field is an RGBQUAD structure that allows setting the Red, Green, and Blue values. The default is white (255, 255, 255).

The output DIB can be cropped to a specified subrectangle by setting F_InputCrop in PicParm.Flags and setting PicParm.IOCropXoff, PicParm.IOCropYoff, PicParm.IOCropWidth, and PicParm.IOCropHeight to describe the subrectangle.  PicParm.IOCropXoff and PicParm.IOCropYoff are offsets within the image dimensions specified with the RenderWidth and RenderHeight fields.

Set CAD.PicFlags |= PF_NoDibPad to avoid any padding of output lines otherwise output lines are padded to a multiple of 4 bytes.

To set the width of the output line to be other than no padding or padding to a multiple of 4 bytes, set CAD.PicFlags |= PF_WidthPadKnown, and set CAD.WidthPad to the desired width in bytes.

CAD files may contain embedded thumbnail previews. If requested, the opcode will return the thumbnail in the form of a DIB.  In order to request a thumbnail, set CAD.PicFlags |= PF_ExpandThumbnail prior to invoking REQ_INIT processing.  If the CAD file contains a thumbnail, the opcode will return the the DIB information in the PicParm.Head field. The DIB can then be obtained by issuing REQ_EXEC, with CAD.PicFlags |= PF_ExpandThumbnail. If the file does not contain a thumbnail, the opcode will return ERR_MISSING_TNUMBNAIL in response to the REQ_INIT. Support is not currently provided for obtaining thumbnails from DWF files. If the file contains a thumbnail, but it is in a format other than an uncompressed bitmap, the opcode will return ERR_UNSUPPORTED_THUMBNAIL_FORMAT.

CAD drawings may contain text elements that rely upon specific fonts. If the specified fonts are not installed on the machine that is running the opcode, the associated text fields may not render as expected.

A CAD drawing may contain Architectural Desktop elements. The opcode does not currently support Architectural Desktop elements, so these elements may not render as expected. Support for Architectural Desktop elements is planned for a future release. 

 

 


©2022. Accusoft Corporation. All Rights Reserved.

Send Feedback