Supplying A Frustrum   

<<< Application Design And Architecture Chapters Further Implementation Decisions >>>

Contents

[back to top]


6.1 Introduction

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:

 

Related Topics:

[back to top]


6.2 What code do you need to supply?

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.

 

Note: Frustrum functions are referred to throughout this guide using the field names below. You can decide on the actual function names yourself, however, since the function names you choose are mapped onto the field names when the frustrum is registered.

6.2.1 Required functionality

You must provide the following frustrum functions:

 

Frustrum control

FSTART

start the frustrum

FSTOP

stop the frustrum

 

File (part data) handling (see Section 6.4, “File handling”)

FFOPRD

open all guises of file (except roll-back) for reading

FFOPWR

open all guises of file (except roll-back) for writing

FFREAD

read from file

FFWRIT

write to file

FFCLOS

close file

 

Memory handling (see Section 6.5, “Memory management”)

FMALLO

allocate virtual memory

FMFREE

free virtual memory

6.2.2 Optional functionality

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.

 

Frustrum control

FABORT

called at the end of an aborted kernel operation

FTMKEY

returns sample name keys (used for testing FFOPRD and FFOPWR)

 

Graphical output (see Section 6.6, “Graphical output”)

GOOPSG

open hierarchical segment

GOSGMT

output non-hierarchical segment

GOCLSG

close hierarchical segment

[back to top]


6.3 Registering the frustrum

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.

[back to top]


6.4 File handling

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.

6.4.1 Structuring the file system for your application

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.

6.4.2 File types and file extensions

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.

 

File type

UNIX/NTFS extensions

FAT extensions

Comment

Transmit (Part)

.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.

Mesh

.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.

Schema

.sch_txt
.S_T

Parasolid uses schema files to read and write data from and to previous versions of Parasolid.

Journal

.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.

Snapshot

.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.

Partition

.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.

Delta transmit

.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.

[back to top]


6.5 Memory management

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.

[back to top]


6.6 Graphical output

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.

6.6.1 Calling PK rendering functions

In order to render part data, your application needs to call a PK rendering function. There are three such functions available:

 

Function

Description

PK_GEOM_render

Renders a geometric entity as a wireframe drawing that is independent of the view required.

PK_TOPOL_render_line

Renders a list of topological entities as either:

  • A view independent wireframe drawing
  • A view dependent wireframe drawing
  • A hidden line drawing

PK_TOPOL_render_facet

Generates a faceted representation of topological entities.

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.

6.6.2 Supplying GO functions

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.

 

Function

Description

GOOPSG

Open a hierarchical segment.

GOSGMT

Output a single-level segment.

GOCLSG

Close a hierarchical segment.

GO functions are registered together with the other frustrum functions. See the Section 6.3, “Registering the frustrum” for details.

6.6.3 Choosing which graphics libraries to use

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.

[back to top]


6.7 Error handling

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.

6.7.1 Handling failures with a non-zero error code

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:

 

Severity

Current state

Required action

Mild

The operation failed but the parts involved were not altered.

Your application can continue as normal.

Serious

The parts involved in the operation may have been altered, and may be invalid as a result. The rest of the Parasolid session is intact.

Your application should roll back to a valid state of the model. If rolling back has not been implemented, it should stop and restart the Parasolid session, and re-register the frustrum and the delta frustrum.

Fatal

The Parasolid session has been corrupted; rolling back, if implemented, will not be effective.

Your application should stop and restart the Parasolid session, and re-register the frustrum and the delta frustrum. Occasionally, it may be necessary for the application to exit.

6.7.1.1 Registering an error handler

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.

6.7.2 Handling failures with a zero error code

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.

 

Warning: For functions that return fault information via their arguments, you should explicitly check the contents of these arguments in your application to establish the success or failure of the operation. A registered error handler will not be called in these situations.

[back to top]


6.8 Starting and stopping a Parasolid session

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.

 

[back to top]

<<< Application Design And Architecture Chapters Further Implementation Decisions >>>