Supplying A Frustrum   

<<< Application Design Chapters The Example Application >>>

Contents

[back to top]


3.1 Introduction

As described in Chapter 2, "Application Design", you need to supply frustrum code to Parasolid in order to perform the following tasks:

This section gives you an overview of what you need to supply in order to accomplish these tasks.

[back to top]


3.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 requred functionality of your application.

The use of the frustrum functions is explained in more detail in Section 3.4, "File handling", Section 3.5, "Memory management", and Section 3.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.

[back to top]

3.2.1 Required functionality

You must provide the following frustrum functions:

 

Frustrum control

FSTART

start up the frustrum

FSTOP

shut down the frustrum

File (part data) handling (see Section 3.4, "File handling")

FFOPRD

open all guises of file (except rollback) for reading

FFOPWR

open all guises of file (except rollback) for writing

FFREAD

read from file

FFWRIT

write to file

FFCLOS

close file

Memory handling (see Section 3.5, "Memory management")

FMALLO

allocate virtual memory

FMFREE

free virtual memory

[back to top]

3.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 initialize 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 3.6, "Graphical output")

GOOPSG

open hierarchical segment

GOSGMT

output non hierarchical segment

GOCLSG

close hierarchical segment

[back to top]


3.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 initialize 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 Appendix B, "Using the PK Interface".

 

PK_SESSION_frustrum_t fru; /* Declare fru as the frustrum */
PK_SESSION_frustrum_o_m( fru ); 
                     /* Initialize 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.

A specific example showing how the frustrum is registered in the Parasolid Example Application is described in Section 4.3, "The frustrum".

[back to top]


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

[back to top]

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

[back to top]

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

Schema

.sch_txt
.sch_bin
.s_t 
.s_b

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. Rollback 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 A, "Further Implementation Decisions" for more information.

Delta transmit

.xmd_txt
.xmd_bin
.d_t 
.d_b

Delta files are used within the rollback 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 A, "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. An example that shows how extensions can be added to filenames is described in Section 4.4.2, "File extensions" in Chapter 4, "The Example Application".

[back to top]

3.4.3 Example file handling code

Section 4.4, "File handling" gives details about how to implement file handling in the frustrum.

[back to top]


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

A specific example showing how memory management functions are used in the Parasolid Example Application is described in Section 4.5, "Memory management".

[back to top]


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

[back to top]

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

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

PK_TOPOL_render_line

Renders a list of topological entities as either:

  • A view independent wire frame drawing
  • A view dependent wire frame 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. This approach may be useful, for instance, if your application needs to perform many calculations on a faceted representation of the model.

[back to top]

3.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 3.3, "Registering the frustrum" for details.

A specific example showing how GO functions are defined in the Parasolid Example Application is described in Section 4.6, "Graphics".

[back to top]

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


3.7 Error handling

Parasolid can raise errors in a number of circumstances. For example, if your application passes incorrect data to a PK function, or a PK function fails in some way, then Parasolid raises an error. Your application needs to be able to handle these sorts of errors. This section describes how you go about doing this.

[back to top]

3.7.1 Choosing an error handling strategy

There are two approaches to handling errors from Parasolid.

The strategy you choose probably depends on how errors are handled by the rest of your application. You are strongly recommended not to mix the two strategies, if this is possible.

Whichever strategy you choose, the same action needs to be taken. This action depends on the severity of the error, as supplied in the error call. See Section 3.7.3, "What to do when an error occurs" for more details.

Registering an error handler

You use PK_ERROR_register_callbacks to register an error handler with Parasolid. When a PK function is about to return an error, the error handler is passed a standard structure (PK_ERROR_sf_t) containing:

This data is always stored, and can be retrieved again if necessary using PK_ERROR_ask_last. The data for the last error can be cleared using PK_ERROR_clear_last.

You can see how an error handler is registered in the Parasolid Example Application in Section 4.7, "Error handling" in Chapter 4, "The Example Application".

[back to top]

3.7.2 Handling non-zero error codes

Every PK function returns an error code that indicates the result of the operation. If this value is zero - PK_ERROR_no_errors - the operation has completed successfully and your application can proceed.

However, if this value is non-zero, then the operation has failed to complete. Each numerical value indicates a predictable error, and your application must handle it appropriately:

 

Note: Do not assume that a a zero error code means that the operation has completed exactly as you intended. A zero error code simply means that the function completed. It is still possible that the operation did not complete in the way you expected, and, in particular, many PK functions return error tokens that indicate specific problems in the values passed to the function or the results produced.

[back to top]

3.7.3 What to do when an error occurs

Whether you register an error handler or decide to handle each error explicitly in your application code, the action that needs to be taken when an error occurs is much the same.

The three error severity levels that your application has to manage are:

 

Severity

Current State

Required Action

Fatal

Modeler memory has been corrupted; rolling back, if implemented, will not be effective. You may not be able to restart Parasolid

Your application should shut down Parasolid

Serious

The parts loaded in Parasolid may be corrupt

If rollback is implemented, your application should roll back to a valid state

Mild

The operation failed; the parts involved were not corrupted

The application can continue with any Parasolid operation

[back to top]


3.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 A.4, "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 Chapters The Example Application >>>