3D PLM Enterprise Architecture |
3D Visualization - Print |
Making Your Components PrintableEnabling your components for print |
Use Case |
AbstractThis article shows how to make your objects printable. |
This use case is intended to show how to make a component printable by making the component implement the CATIPrintable interface.
[Top]
CAAPrtPrintableObjects is a use case of the CAAPrint.edu framework that illustrates the Print framework capabilities.
[Top]
CAAPrtPrintableObjects is a program that creates a simple component using a
single class named CAAPrtPrintableString that holds a character string.
This component implements the CATIPrintable interface [1]
and its single method CreatePrintableImage
that creates and returns
the component printable image. This is an instance of the CAAPrtStringImage
class.
[Top]
To launch CAAPrtPrintableObjects, you will need to set up the build time environment, then compile CAAPrtPrintableObjects along with its prerequisites, set up the run time environment, and then execute the use case [2].
[Top]
The CAAPrtPrintableObjects use case is made of a several classes located in the CAAPrtPrintableObjects.m module of the CAAPrint.edu framework:
Windows | InstallRootDirectory\CAAPrint.edu\CAAPrtPrintableObjects.m\ |
Unix | InstallRootDirectory/CAAPrint.edu/CAAPrtPrintableObjects.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
To make a component printable, there are four main steps:
# | Step | Where |
---|---|---|
1 | Makes the component implement CATIPrintable | CAAPrtPrintableString class |
2 | Creates the printable image class | CAAPrtStringImage class |
3 | Writes the GetSize method |
CAAPrtStringImage class |
4 | Writes the Decode method |
CAAPrtStringImage class |
The CAAPrtPrintableString component is created using a single class whose name is the component name.
[Top]
The CAAPrtPrintableString class header file is as follows.
#include "CATBaseUnknown.h" // To derive from CATBaseUnknown #include "CATUnicodeString.h" // The string to represent class CATPrintImage; // To return the image class CAAPrtPrintableString : public CATBaseUnknown { public: CATDeclareClass; // Declares that this class belongs to a component CAAPrtPrintableString (const CATUnicodeString & iString); virtual ~CAAPrtPrintableString (); // CATIPrintable interface method CATPrintImage * CreatePrintableImage(void); // Returns the image representing the string private: CATUnicodeString _string; // The string to print held by the component }; |
The CATDeclareClass
macro declares that this class is part of a
component. The class has a constructor that takes the character string as input
parameter, a destructor, the CreatePrintableImage
method of the CATIPrintable
interface, and the character string.
Its source file is a follows.
#include "CAAPrtPrintableString.h" // Header of the current class #include "CAAPrtStringImage.h" // The class of the image to print // Print framework #include "TIE_CATIPrintable.h" // Declares that this class implements the CATIPrintable interface TIE_CATIPrintable(CAAPrtPrintableString); // Declares that this class is an implementation CATImplementClass(CAAPrtPrintableString, Implementation, CATBaseUnknown, CATnull); CAAPrtPrintableString::CAAPrtPrintableString(const CATUnicodeString & iString) : _string(iString) {} CAAPrtPrintableString::~CAAPrtPrintableString() {} // CATIPrintable implementation // Returns the image representing the printable object CATPrintImage * CAAPrtPrintableString::CreatePrintableImage(void) { return new CAAPrtStringImage(_string); } |
The TIE_CATIPrintable
macro creates a TIE object that decouples
the interface and its implementation. Clients that hold a pointer to the CATIPrintable
interface have in fact a pointer to the TIE object, and not to the CAAPrtPrintableString
instance.
The CATImplementClass
macro declares that the CAAPrtPrintableString
class is an implementation, that is, the component main class, other possible
classes making up the component being extensions, and that the component
OM-derives from CATBaseUnknown.
The implementation of the CreatePrintableImage
method of CATIPrintable
simply returns an instance of the CAAPrtStringImage class.
The framework's interface dictionary should include the following line.
CATPrtPrintableString CATIPrintable libCAAPrtPrintableObjects |
This declares that the CATPrtPrintable component implements the CATIPrintable interface, and that the implementation code is located in the shared library or DLL named libCAAPrtPrintableObjects. If the TIE and the method code are located in two different shared libraries or DLL, the one that must be inserted in the interface dictionary is the one that contains the TIE code.
[Top]
The printable image class header file is as follows.
... class CATPrintGenerator; // To use a generator to draw the image class CATPrintParameters; // To use print parameters class CAAPrtStringImage : public CATPrintImage { public: CAAPrtStringImage(const CATUnicodeString &iString); virtual ~CAAPrtStringImage(); // Retrieves the image size int GetSize(float& iWidth, float& iHeight); // Draws the image using a given generator and specified print parameters int Decode(CATPrintGenerator* iGenerator, const CATPrintParameters& iParameters); private: CATUnicodeString _string; // The string to draw }; |
This class holds the character string, and has two methods
GetSize
to determine and return the printed component sizeDecode
that draws the component image to print using a set of
print parameters.[Top]
... int CAAPrtStringImage::GetSize(float& oWidth, float& oHeight) { // The size depends on the string length int lg = _string.GetLengthInChar(); oHeight = 50.f; oWidth = (lg+4)*10.; return 1; } ... |
GetSize
determines the character string length expressed in
number of characters, and computes from this length a height and a width of the
character string to print.
[Top]
... int CAAPrtStringImage::Decode(CATPrintGenerator* iGenerator, const CATPrintParameters& iParameters) { iGenerator->Begin(iParameters); // Initializes generation ... iGenerator->End(); // Ends generation return 1; // Returns 1 to indicate successful execution } ... |
The Decode
method encloses its code between the call to the
generator Begin
method with the print parameters, and the call to
the generator End
method, just before returning. Now have a look at
what can be put between these two method calls.
... iGenerator->SetDrawWidth(0.0f); // Sets line width int Black=0; // Defines the black color iGenerator->DefineColor(Black, 0.0f, 0.0f, 0.0f); int Red =1; // Defines the red color iGenerator->DefineColor(Red, 1.f, 0.f, 0.f); iGenerator->SelectDrawColor(Black); // Sets the black color as the drawing color // Defines the text direction: horizontal, from left to right iGenerator ->SetTextAttribute(CATPRINTTEXT_DIRECTION, 0.0); // Sets the Courier font iGenerator ->SetTextAttribute(CATPRINTTEXT_TYPEFACE, CATPRINTTEXT_COURIER); // Requests bold caracters iGenerator ->SetTextAttribute(CATPRINTTEXT_WEIGHT, CATPRINTTEXT_BOLD); // Defines the character height iGenerator ->SetTextAttribute(CATPRINTTEXT_HEIGHT, 16.72); ... |
Some initializations are first performed, such as the drawing line width, the black and red colors, the black color being set as the color to use, and some attributes of the text to print.
... int lg = _string.GetLengthInChar(); float y = 10.; float x = 10.; float x0 = x; float y1 = 4*y; float y0 = y; float x1 = (lg+3)*x; // Draws the string iGenerator ->DrawGeometricText(x0+x, y0+y, _string); iGenerator->SelectDrawColor(Red); // Sets the red color as the drawing color iGenerator->MoveTo(x0, y0); // Moves to the bottom left corner of the frame for (int i=1; i<=lg+2; i++) // Draws a bottom zigzag line { iGenerator->LineTo(x0+i*x-x/2, y0-y/2); iGenerator->LineTo(x0+i*x, y0); } ... |
The text is drawn first in black using the DrawGeometricText
method, and it is then surrounded by zigzag lines drawn in red. The red color is
selected using the DrawGeometricText
method.The pen moves to the
(x0,y0) point, and then the bottom zigzag line drawing begins. The three others
zigzag line drawing are not shown.
[Top]
This use case shows the objects involved and what to do to make a component
printable. The component must implement the CATIPrintable interface whose
single method CreatePrintableImage
returns an object that bears two
methods: GetSize
that defines the print size from the component
contents, and Decode
that decodes this component contents and that
actually prints it.
[Top]
[1] | Making Your Components Printable |
[2] | Building and Launching a CAA V5 Use Case |
[Top] |
Version: 1 [Jan 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.