3D PLM Enterprise Architecture

3D Visualization - Print

Converting Print Files

Creating a TIFF file from a CGM file

Use Case

Abstract

This article discusses the CAAPrtChangeFormat use case. This use case explains how to convert an input file encoded using a given format into an output file encoded using another format.


What You Will Learn With This Use Case

This use case is intended to show how to convert an input file encoded using a given format into an output file encoded using another format. To do this, you'll learn how to create a print file image from the input file, a print device, print parameters, and how to generate the output file encoded using the target format.

[Top]

The CAAPrtChangeFormat Use Case

CAAPrtChangeFormat is a use case of the CAAPrint.edu framework that illustrates Print framework capabilities.

[Top]

What Does CAAPrtChangeFormat Do

CAAPrtChangeFormat is a batch program that reads a CGM file from the command line and converts it into a TIFF file.

[Top]

How to Launch CAAPrtChangeFormat

To launch CAAPrtChangeFormat, you will need to set up the build time environment, then compile CAAPrtChangeFormat along with its prerequisites, set up the run time environment, and then execute the use case [1].

In addition, the CAAPrtOut environment variable should be set to the directory into which you want to create the resulting TIFF file, prior to launching CAAPrtChangeFormat with the path of the input CGM file as argument.

where:

[Top]

Where to Find the CAAPrtChangeFormat Code

The CAAPrtChangeFormat use case is made of a single source file located in the CAAPrtChangeFormat.m module of the CAAPrint.edu framework:

Windows InstallRootDirectory\CAAPrint.edu\CAAPrtChangeFormat.m\src\CAACPrtChangeFormat.cpp
Unix InstallRootDirectory/CAAPrint.edu/CAAPrtChangeFormat.m/src/CAACPrtChangeFormat.cpp

where InstallRootDirectory is the directory where the CAA CD-ROM is installed.

[Top]

Step-by-Step

To create the CGM to TIFF CAAPrtChangeFormat format converter, there are six main steps:

  1. Initializing the Printer Manager
  2. Creating a Print File Image from the Input File
  3. Creating a Print Raster File Device
  4. Defining Print Parameters
  5. Writing the Output File
  6. Cleaning the Application and Closing the Printer Manager

Some preliminary tasks are not described. They deal with retrieving the input file name, finding out the output file directory, and building the output file name. The input file name is retrieved from the command line in the InputName variable, such as TestFile.cgm. The file extension is compared with cgm. The output file directory is given by the CAAPrtOut environment variable, which you have to export. The output file name uses the input file name and changes its suffix to tif, such as TestFile.tif and is stored in the TmpFile variable.

[Top]

Initializing the Printer Manager

#include "CATPrintFileImage.h"   // To create an image from the input file
#include "CATPrintParameters.h"  // To define print parameters
#include "CATPrintFileDevice.h"  // To create a file device
...

int main(int argc, char* argv[])
{
  int ReturnCode = 0;
  ... // Retrieving the input file name, setting the output file directory, and
  ... // building the output file name is not described here
     
  CATPrinterManager::Begin();
  ...

As soon as the input file is retrieved and the output file directory and name are set, the printer manager is initialized.

[Top]

Creating a Print File Image from the Input File

As soon as the input file is retrieved and the output file directory and name are set, the print file image can be built from the input file.

  ...     
  CATPrintFileImage *pImage;
  pImage = new CATPrintFileImage(InputName, "CGM");
  ...

This print file image is an instance of the CATPrintFileImage class instantiated from the input file. The input file format is passed as the second argument, here CGM. The print file image created holds the input file in memory and the CGM interpreter to enable the file interpretation as soon as this will be asked.

[Top]

Creating a Print Raster File Device

The print raster file device should be next instantiated.

  ...
  CATPrintFileDevice *pDevice;
  pDevice = new CATPrintFileDevice( (const char*) TmpFile, "RASTER" );
  ...   

The print raster file device represents the output logical unit for a real device. It is made of a TIFF generator and of a stream into which the TIFF image writing will be performed. For this reason, the output file name and the RASTER type, that stands for TIFF, are passed as arguments.

[Top]

Defining Print Parameters

A print parameter object should be defined to be associated with the print file image to convert.

  ...
  CATPrintParameters Parameters;

  Parameters.SetWhitePixel(1);                               // Print white pixels white
  Parameters.SetMapToPaper(1);                               // Resize image to match paper format
  Parameters.SetBanner("CAAPrtChangeFormat");                // Add a banner
  Parameters.SetBannerPosition(CATPRINT_TOP);                // at the top of the image
  Parameters.SetLineWidthSpecificationMode(CATPRINT_SCALED); // Change line width with scale
  Parameters.SetLineTypeSpecificationMode(CATPRINT_SCALED);  // Change non continuous lines with scale
 
  float imageWidth=0, imageHeight=0;
  int result = pImage->GetSize(imageWidth, imageHeight); // Retrieve input file dimensions
  if (result)
  { 
    // Set the output image dimensions: width increases from 50%, height doesn't change
    CATPrintForm CurrentForm = Parameters.GetCurrentForm();
    CurrentForm().SetSize(imageWidth*1.5, imageHeight);
  } 
  ...

The print parameters are taken into account to create the output image. The following parameters are set:

Other print parameters take their default values.

[Top]

Writing the Output File

The file conversion can now take place.

  ...
  if ( !pImage->Print(pDevice, Parameters) )
  {
    cout << " Error during printing " << endl;
    ReturnCode = 1;
  }    
  ...

The Print method converts the print file image from CGM to TIFF using the parameters set, and writes the output to the print raster file device.

[Top]

Cleaning the Application and Closing the Printer Manager

  ...
  delete pDevice;
  delete pImage;
  CATPrinterManager::End();
  return ReturnCode;
}

Simply don't forget to delete allocated objects, close the Printer Manager, and return the appropriate return code.

[Top]


In Short

This use case shows the objects involved when converting a print file, here encoded using CGM, into another file encoded using another format, here TIFF. These objects are the print file image, the print raster file device, and the set of parameters that are needed to create the TIFF file.

First, the Printer Manager is initialized. Then, a CATPrintFileImage instance is created using the input file, and a CATPrintFileDevice instance is created using the target file format to accommodate the output TIFF file. A CATPrintParameters instance is created and valued using the appropriate setters to hold the intended print parameters. Finally, the Print method of the CATPrintFileImage class is used to generate the TIFF file, and the Printer Manager is closed.

[Top]


References

[1] Building and Lauching CAA V5 Samples
[Top]

History

Version: 1 [Jan 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.