3D PLM Enterprise Architecture |
3D Visualization - Print |
Converting Print FilesCreating a TIFF file from a CGM file |
Use Case |
AbstractThis 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. |
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]
CAAPrtChangeFormat is a use case of the CAAPrint.edu framework that illustrates Print framework capabilities.
[Top]
CAAPrtChangeFormat is a batch program that reads a CGM file from the command line and converts it into a TIFF file.
[Top]
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.
E:>set CAAPrtOut=DirForOutputTIFFFile E:>CAAPrtChangeFormat InstallRootDirectory\CAAPrint.edu\CNext\resources\graphic\images\CAAPrtChangeFormat.cgm |
$ export CAAPrtOut=DirForOutputTIFFFile $ CAAPrtChangeFormat InstallRootDirectory/CAAPrint.edu/CNext/resources/graphic/images/CAAPrtChangeFormat.cgm |
where:
DirForOutputTIFFFile
is the directory where the TIFF will be
createdInstallRootDirectory
is the directory into which the CAA
CD-ROM were unloadedCAAPrtChangeFormat.cgm
is a sample CGM file. You can use
other CGM files you may have at hand.[Top]
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]
To create the CGM to TIFF CAAPrtChangeFormat format converter, there are six main steps:
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]
#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]
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]
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]
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:
GetSize
method, and the new size is set as a print
parameter through the CATPrintForm instance retrieved using the
GetCurrentForm
method from parameters
.Other print parameters take their default values.
[Top]
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]
... 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]
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]
[1] | Building and Lauching CAA V5 Samples |
[Top] |
Version: 1 [Jan 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.