![]() |
Supplying A Frustrum |
<<< Application Design And Architecture | Chapters | Further Implementation Decisions >>> |
This chapter gives you an overview of what you need to do in order to integrate Parasolid into your application. It includes the following sections:
This section outlines the frustrum functions that you need to supply in order to build a working frustrum. Some functions are optional; what you need to supply depends on the required functionality of your application.
The use of the frustrum functions is explained in more detail in Section 6.4, “File handling”, Section 6.5, “Memory management”, and Section 6.6, “Graphical output” later on in this chapter.
You must provide the following frustrum functions:
File (part data) handling (see Section 6.4, “File handling”) |
|
---|---|
Memory handling (see Section 6.5, “Memory management”) |
|
---|---|
You can choose whether to implement the following frustrum functions. If you do not, they should be left as NULL. When you initialise the frustrum, all available functions are set to NULL, so you can effectively ignore any functions listed here that you don’t require.
returns sample name keys (used for testing FFOPRD and FFOPWR) |
Graphical output (see Section 6.6, “Graphical output”) |
|
---|---|
Before you can start the modeler and make PK calls, you need to register the frustrum functions with Parasolid. To do this, use the PK function PK_SESSION_register_frustrum,which takes a list of pointers to the frustrum functions you have supplied.
You declare and initialise the frustrum in the same way that you set up any option structure in the PK. The following code extract shows how this might be done. For more details, refer to Section 9.2, “PK functions”.
PK_SESSION_frustrum_t fru; /* Declare fru as the frustrum */ PK_SESSION_frustrum_o_m( fru ); /* Initialise the frustrum functions */ /* Point to each of the frustrum functions you are supplying */ fru.fstart = MyAppStartFrustrum; fru.fabort = MyAppAbortFrustrum; fru.goopsg = MyAppOpenSeg;/* Note: Many functions missing from the list above */ /* Register the frustrum with Parasolid */ PK_SESSION_register_frustrum( &fru ); |
In the code above, note that MyAppStartFrustrum represents a function that you have actually supplied a definition for, and fstart represents a field required by PK_SESSION_register_frustrum.
The files that Parasolid uses for storing part data are referred to as ‘transmit’ or ‘XT’ files. In order to transfer data through the frustrum, you need to write to and read from these files. Parasolid can also use several other file types, as described in Section 6.4.2, “File types and file extensions”. You need to decide the format and location of these files in order to write your frustrum functions.
For an example of this functionality, see the code example in the
C++\Code Examples\Application
support\Downward
Interfaces\Frustrum
folder, located in
example_applications
in your Parasolid installation folder.
You can configure Parasolid to handle many different kinds of archiving systems, such as:
Your application should provide the following functionality for managing the files generated and required by Parasolid.
The frustrum is passed a key (a text string) that identifies the part. This key can be used as a filename or as an index into the database, depending on the archiving system you have chosen.
Parasolid uses several file types, each of which can be written in one of the following formats:
At a minimum, your application must support Transmit files. Depending on its functionality, it may also need to deal with some of the other file types described here.
Each file type has a recommended file extension that is also dependent on the file system you are writing to or reading from, as shown in the table below. Note that file extensions ending in
_t
or
_txt
denote text-based formats, and extensions ending in
_b
or
_bin
denote binary-based formats.
.xmt_txt .xmt_bin |
.X_T .X_B |
Transmit (or XT) files are used to store part or assembly data and are often used for transferring data between Parasolid-powered systems. |
|
.xmm_txt .xmm_bin |
.M_T .M_B |
Mesh data of a facet body can either be embedded in the XT file, or stored externally in separate mesh files that have the same key as the corresponding transmit or partition file. See Chapter 82, “Overview Of Convergent Modeling” for more information on mesh data. |
|
.sch_txt |
.S_T |
Parasolid uses schema files to read and write data from and to previous versions of Parasolid. |
|
.jnl_txt .jnl_bin |
.J_T .J_B |
Journal files are used to keep a record of all of the commands issued to Parasolid within a session. Journal files can be used for debugging. |
|
.snp_txt .snp_bin |
.N_T .N_B |
A snapshot file is a memory dump of a Parasolid session. These files are very rarely used, but are sometimes useful for reproducing faults. |
|
.xmp_txt .xmp_bin |
.P_T .P_B |
Partitions enable related parts to be archived as a single item. Roll-back information allows your application to return a Parasolid session to an earlier state. If your application uses either of these mechanisms, the relevant data is written to a partition file. See Chapter 7, “Further Implementation Decisions” for more information. |
|
.xmd_txt .xmd_bin |
.D_T .D_B |
Delta files are used within the roll-back mechanism and are controlled by a separate suite of functions called the delta frustrum. Delta transmit files are an aggregate of all existing delta files, and their creation is controlled by the frustrum. See Chapter 7, “Further Implementation Decisions” for more information. |
The file handling functions in your frustrum must handle all the file types that you decide to support, adding the appropriate extensions. These functions may also test whether a file resides on a DOS style FAT device or a long filename NTFS type device before adding the extension, unless you decide to support only the FAT extensions, regardless of the filesystem. If you support both FAT and NTFS extensions, files can simply be renamed when transferring between the different systems.
You need to supply two memory management functions in the frustrum that allow Parasolid to allocate and free memory for its use. These functions control the way that memory is allocated to and freed for use in:
The memory management functions are FMALLO (allocate virtual memory) and FMFREE (free virtual memory).These functions map closely to the C functions malloc and free, and any function definitions you supply should be type-compatible with malloc and free.
You could consider implementing some buffering in order to improve performance compared to the standard functions. For example, with suitable definitions for FMALLO and FMFREE:
The memory management functions are registered when registering the frustrum.
See Section 9.3, “Memory management”, for more information on memory management.
If your application needs to display parts - whether by rendering them on screen, or printing them to a plotter or laser printer - you need to do three things:
When a call is made to one of the PK rendering functions, the graphical data output by Parasolid is passed to the GO functions, which catch and interpret the data, filter it, and use the functionality of the graphics library to render the parts on the appropriate device.
For an example of this functionality, see the code example in the
C++\Code Examples\Application
support\Downward
Interfaces\Go
folder, located in
example_applications
in your Parasolid installation folder.
In order to render part data, your application needs to call a PK rendering function. There are three such functions available:
Renders a geometric entity as a wireframe drawing that is independent of the view required. |
|
Each of these functions uses the supplied GO functions to pass graphical data to the appropriate graphics library.
The PK outputs graphical information in the form of segments. These correspond to identifiable portions of the model being rendered, and can be curves or facets (depending on the PK function used). There are two types of segments:
Note: It is possible to generate faceted information without using the GO, by using the function PK_TOPOL_facet_2. This approach may be useful, for instance, if your application needs to perform many calculations on a faceted representation of the model. |
Parasolid passes segment data to the GO functions. These functions use the supplied graphics libraries and may generate, for example, screen pictures, plot files and laser print files.
There are three GO functions in the frustrum. They all take the same arguments, but interpret them in different ways.
GO functions are registered together with the other frustrum functions. See the Section 6.3, “Registering the frustrum” for details.
Parasolid’s graphical data output can be used in conjunction with many different graphical libraries. You must supply a graphics library for every device you want to use for rendering output. If your application renders to several different devices (for instance, it might render to the screen, and print paper copy), then you may need to supply several different libraries. You can write your own graphics libraries if you wish, or you can use third party libraries. The GOSGMT function calls the appropriate libraries in order to perform the necessary rendering.
Parasolid errors can occur in a variety of situations. For example, if your application passes incorrect data to a PK function, or a PK function fails to complete an operation, Parasolid sends a non-zero error code to your application. In other situations, more details concerning the nature of the failure can be returned. In these situations, a value of zero is returned as the error code, and the information is sent back via a status code among the output arguments of the function.
There are two main decisions to make when deciding how to handle these errors:
Your application can write and register a particular function, known as an error handler, with Parasolid. This function will be called whenever an error occurs, to perform certain recovery tasks. Parasolid automatically invokes this error-handling function just before returning from a failing PK function, which means that the application does not have to deal with PK errors explicitly.
In addition, your application can choose whether to throw an exception when it encounters an error, via the
try/throw/catch
statements in C++ (or the equivalent
setjmp/longjmp
functions in C). This allows program execution to avoid some sections of code, and resume in a convenient place once the error has been dealt with. If your application uses a registered error handler combined with exceptions, it does not need to check the return status of each PK function before proceeding.
Whichever strategy you choose, the same recovery action needs to be taken at some point. This action depends on the severity of the error, as described in the following table:
You register an error-handling function with Parasolid by calling PK_ERROR_register_callbacks. Your error handler must receive a pointer to a PK_ERROR_sf_t structure and have the return type PK_ERROR_code_t, although it need not necessarily return a value, as this is not used by Parasolid. The PK_ERROR_sf_t structure contains details of the error such as the name of the failing function, the error code, and the severity of the error.
Warning: Your error handler should not attempt to alter any details of the current error (by modifying the PK_ERROR_sf_t structure, or returning a different error code). Parasolid stores this information separately, and so any such alterations would have no effect. |
The documentation for each Parasolid function indicates whether it may return failure information through a status code, and if so, which variable contains the status code.
You use the function PK_SESSION_start to start the Parasolid modeler. This takes an options structure that you can use to specify session specific options, as described in Section 7.5, “Session parameters”.
You use the function PK_SESSION_stop to stop the Parasolid modeler.
Warning: You
must register the frustrum before attempting to start a Parasolid session. |
<<< Application Design And Architecture | Chapters | Further Implementation Decisions >>> |