|
SilverScreen API Reference |
|
The SilverScreen API is the common set of functions used to develop applications with SilverScreen Solid Modeling technologies. The modeling software supports three platforms:
Each of these platforms has available the full functionality of the SilverScreen Solid Modeler. This functionality includes:
In this manual, we assume some familiarity with the C/C++ languages and SilverScreen operation, plus some understanding of 3D concepts. For more complete coverage of SilverScreen, see the SilverScreen Reference Manual. This document describes the SilverScreen API, and is divided into several parts:
Important type styles and conventions used in this document:
The distribution toolkit includes a number of header files that are used to define various objects used by the SilverScreen developer. There are two types of headers: SilverScreen-specific headers and Standard C compatible headers. The SilverScreen-specific headers are provided specifically for interfacing with SilverScreen-specific functions and structures. The Standard C headers are provided for compatibility with Standard C. The SilverScreen-specific headers are the following:
It is of interest to note that SilverScreen shares these exact includes, and hence the same data structures. SILVER.H -- General SilverScreen Access SILVER.H contains structures and definitions that are of common use in the SilverScreen API. The file includes the code and bit definitions necessary for identifying primitives and entities. Structures for the load functions (load_variable and load_attribute) also appear in this file. SILVER.H includes SSDEF.H, SSNODES.H and SSKEYS.H, making access to all SilverScreen API functionality a simple matter. SSNODES.H -- Direct SilverScreen Access ssnodes.h provides definitions for the SilverScreen internal structures. Descriptions of these structures appears in the section on SilverScreen Internal Structures. SSKEYS.H -- Input Events sskeys.h provides definitions for keys and events returned by the predefined SilverScreen functions inchar and nextkey . SSDEF.H -- Basic SilverScreen Type Definitions ssdef.h provides basic definitions used commonly in SilverScreen. |
|
Script Commands
The script command is a primary means of communication between programs and the SilverScreen. The ss_command function, available in SilverC and C++, sends commands to SilverScreen for processing. In this section we will describe how the script command fits into the overall structure of the SilverScreen API. SilverScreen is a command-based system. Every activity, interactive or otherwise, is executed by means of a command. Below is a schematic that shows the relationship between the three systems that operate within interactive SilverScreen.
Here are the steps that occur in the interactive selection and execution of a command.
The commands that are passed from the Menu System to the Interactive System are called icommands (interactive commands). The commands between the Interactive System and the Execution System are simply called commands. (The word "command" is often used generically to refer to either a command or an icommand.) Example: A user selects Draw Polygon from the menu. The Menu System issues an icommand which is sent to the Interactive System. Here is the icommand:
When the Interactive System receives this command, it prompts the user for a set of polygon points. Let us assume that the user selects five points. Then the commands sent by the Interactive System to the Execution System might be as follows:
These commands will cause the Execution System to draw a polygon on the screen and to include the polygon within the drawing database. Application Programs and Commands SilverScreen is designed so that the Interactive and Execution Systems are independent of the source of the commands that they process. That is, these systems do not know whether a command comes from an interactive user or from an application program. Using the ss_command function, a C++ or SilverC application program can send the icommand
The Interactive System will respond to this icommand exactly as if the icommand were sent from the Menu System. That is, it will prompt the user for a set of points. After the user has supplied the points, it will then send commands to the Execution System to draw the polygon. Application programs can also use ss_command to send commands directly to the Execution System. The following command will rotate a block about the y-axis.
ss_command function provides the full power of SilverScreen, both at the interactive level and the execution level, available to the application program. ss_command is a member of the printf family of functions. It uses formatting descriptors such as %d and %s in the same manner as printf. In additon to the descriptors supported by printf, ss_command also supports one additional descriptor, %z. This descriptor allows for easy formatting of variables of the type SS_XYZ. The SS_XYZ structure is used to store three-dimensional coordinates. The structure has three components:
The %z descriptor requires a pointer to a variable of type SS_XYZ. Let us assume that p1, p2, and p3 contain the coordinates of three points. Then ss_command can be used to draw a triangle as follows:
The use of the %z descriptor is equivalent to the use of three comma-separated %.15g descriptors. Without using %z, the above statements can be rewritten as:
The following program begins by opening a drawing with the name machine. The viewing mode is set to perspective, and the drawing is zoomed so that it appears at the center of the screen. The horizonal angle of view is then altered 12 times, each time by 30 degrees. With each change in view, the drawing is rendered and a BMP image is exported. After unloading the drawing, the 12 BMP images are successively displayed on the screen. int i; SilverScreen supports three types of coordinate systems: W-Space (world space), C-Space (construction space), and E-Space (entity space). The W-Space coordinate system corresponds to the standard Cartesian coordinate system. C-Space refers to a three-dimensional coordinate system that can be oriented anywhere in the world coordinate system. Interactive users frequently use C-Space for their drawing activities. E-Space is a local coordinate system that stored with each entity. When an entity is created, the E-Space of the entity is initialized to the C-Space that is current at the time that the entity is created. When an entity is rotated or moved, the E-Space of the entity is also rotated or moved along with the entity. There are a number of commands that can be used to define a C-Space. Two of these commands are illustrated below. The first command defines the C-Space according to an origin point and the direction of the x and y axes. The second command aligns the C-Space to the E-Space of a object with the name \room2\wall2.
In application programs, it is very useful to be able to execute SilverScreen commands relative to C-Space. The following two commands draw lines in W-Space.
By enclosing the coordinates by square brackets, the points are interpreted to be C-Space points. The first command below will draw a line between C-Space points 2,3,4 and 1,1,5. This is shown below.
C-Space Coordinates: An Example The function draw_frame, shown later in this section, draws a frame in C-Space. The frame will be of height h and width w, and will consist of four solid members. The members will be of thickness t and depth d.. Here is a front view of the frame: The orientation of the frame is determined by the parameters origin, xaxis, and yaxis. The lower left corner of the frame will be constructed at origin. The frame will extend to the right in the direction of xaxis, and will extend upward in the direction of the yaxis. The draw_frame function begins by aligning the C-Space to the parameters origin, xaxis, and yaxis. Four polygons are then drawn within the object temp. Note that the function draw_polygon draws these points in C-Space. The solids are then created by sweeping all four polygons in a single operation. The direction and depth of the sweep is determined by the C-Space points [0,0,0] and [0,0,d]. This specifies a sweep of distance d along the z-axis of the C-Space.
SilverScreen has several thousand commands and variations of commands. To use a specific command in a program, it is necessary to know the exact format of that command. There are three ways to find the format. The most obvious (and least useful) method is to search the reference manual of the SilverScreen Solid Modeler. This manual contains a complete listing of all commands. In practice, however, this is seldom done. It is much easier to find the format of a command by simply executing the command in SilverScreen. Since all executed commands and icommands are recorded in the command log, it is a simple matter of executing the command and viewing the command log. It is very common for programmers to execute commands then copy those commands directly from the log to their program. On occasion, there may be long sequences of commands that are required in a program. For example, one may require commands to draw polygons and circles, perform Boolean operations, and to sweep and render. In this case, Remember Mode is a very good tool. When Remember Mode is enabled, all commands are recorded into a script file. The recording of commands continues until Remember Mode is disabled. At the end of the recording session, the script file will contain a faithful record of all commands that were executed. |
| Drawing Hierarchy
The SilverScreen internal drawing structure closely resembles the Windows file system. Whereas the Windows file system contains folders and files, the SilverScreen drawing structure contains blocks and entities. Entities: An entity may be a block, an object, a text line, a detail, or a symbol. Each entity has a name that is unique within the block that contains the entity. This name is assigned to the entity when the entity is created. The entity structure for a drawing may be displayed with the STRUCTURE TREE command. Blocks: The block is an organizational unit that contains contain zero or more entities. At the root of the drawing structure is a block that is referred to as the root block. Objects: The object entity is the container of geometry in a SilverScreen drawing. An object contains zero or more primitives where each primitive is a basic drawing element such as a polygon, a line, a circle, or a curve. The object also contains an edge list and a vertex list. These lists are referenced by the primitives. Text Lines: The text entity is a collection of text characters that form a single line of text. The font for a text entity may be a TrueType font or a SilverScreen stroke font. The characters of the text line are viewed through a transformation matrix that allows the text entity to be displayed in 3D space. Details: The detail entity are used to provide annotation for the drawing. There are about 15 types of details that are used to display angles, linear distances, Y14.5 information, and notes. All detail entities are contained within special blocks called annotation blocks. Symbols: The symbol entity is a reference to an internal model or to a model that resides in an external model library. Symbols allow the geometry of the model to be reused. Through a transformation matrix local to the symbol, the geometry of the model may be translated, scaled and rotated. A model may be either a block or an object. Primitives: Primitives are always contained within objects. Primitive types include arcs, curves, circles and ellipses, lines, points, and polygons. Each primitive is identified by a identification number that is unique within the object that contains the primitive. Complex primitives (such as polygons) are composed of simple primitive types (lines and arcs). Information about primitives may be displayed with the STRUCTURE LIST command. All entities and primitives are directly accessable by application programs. Entity and primitive structures are described in SilverScreen Internal Structures. Structures representing entities:
Structure representing primitives:
Pointers to entity structures may be obtained via the get_bos function. Pointer to primitive structures are obtained either via the get_prim function, or by accessing the first_node field in an OBJECT_NODE . Although the structure for each type of entity is unique, there is a structural prefix that is common to all entity types. For convenience, these common fields are defined as an independent structure called the BOS_NODE. Informally, we speak of the of entity nodes as being BOS nodes. In actuality, there is no entity whose structure corresponds exactly with the structure of the BOS_NODE. Here is the BOS_NODE structure:
This structure contains:
An entity may be a block, an object, a symbol, a detail, or a text line. To distinguish between the different entity types, the bits1 field in the BOS_NODE can be examined. A specific bit of this field is set for each of the five entity types. The E_OBJECT bit (0x0002) is used to identify objects. If this bit is set then the entity is an object. Similar bit settings are defined in SSNODES.H for the other entity types:
Here is an example showing how entities might be identified:
The annotation block (A-Block) has a special purpose within the SilverScreen hierarchical structure. This type of block is used to store the details (and possibly other entities) that belong to a specific annotation block. A-blocks always appear at the root and can be identified through the bits2 field and the IS_ANNOTATE definition. An A-Block is identified below:
The BLOCK_NODE structure is shown below. Note that the first portion of the structure is identical to that of the BOS_NODE.
The BLOCK_NODE structure contains first_bos, a pointer to the first entity within the block. To access the entities within a block, the first_bos pointer is used to locate the first entity of the block. Once this first entity has been located, the next_bos pointer can then be used to traverse the list of entities within the block. The list terminates with a null pointer. The following will display the entity names of a drawing in in-order sequence. Note that the function display_block is used recursively.
Note the manner in which the BOS_NODE pointer bos is cast to a BLOCK_NODE pointer. This technique is frequently used in accessing drawing structures. That is, the bits of the BOS_NODE are examined to determine the entity type of the node. If the bit setting in bits1 corresponds to that of an OBJECT_NODE, then the BOS_NODE pointer is cast to an OBJECT_NODE pointer. The OBJECT_NODE is the organizational unit for the drawing primitives within a drawing. Each object has a pointer to the first primitive within the list of primitives contained in the object. These primitives may have pointers to other primitives. The organization of this structure is described in the next section. The SYMBOL_NODE contains a pointer to a MODEL_NODE. The MODEL_NODE contains a pointer to a BLOCK_NODE which in turn contains a pointer to the first BOS_NODE within the model. The geometry of the model is viewed through the transformation matrix contained in the SYMBOL_NODE. Since the MODEL_NODE may contain symbols that have their own transformation matrices, the viewing of points should be handled with composite transformation matrices using a push-pop technique. Blocks, symbols, and objects may be associated with schema. Thus the BLOCK_NODE, SYMBOL_NODE, and OBJECT_NODE each have a pointer to the to the first SCHEMA_NODE in a list of SCHEMA_NODEs. Each of the SCHEMA_NODEs has a pointer the first ATTRIBUTE_NODE in a list of ATTRIBUTE_NODEs. Primitives are only contained in objects. The following primitives are supported in SilverScreen. Each of these primitive types has a structure definition. The names of these structures are:
All primitives are directly or indirectly contained in objects. However, primitives may be contained within other primitives. A polyline, for example, consists of a set of lines; a Bezier curve consists of a set of Bezier points. The following summarizes the rules of association for primitives:
Holes give a second level of association for certain primitives. Here are the rules of association for holes:
Another level of associativity is the phantom. Phantoms give additional information about a primitive. To understand the use of the phantom, consider the following: A rectangle is drawn and filleted on all four corners. This results in a polygon that consists of four lines and four arcs. This polygon is then swept linearly to produce a solid. Since the SilverScreen solid consists of polygons that contain only lines, the arc information would seemingly be lost in producing the solid. However, to retain this arc information, a new association is formed. This association relates the polygon to the arcs that, prior to the sweep, were part of the polygon. Arcs (and circles) of this type are called phantoms. Phantoms, while not visible on the screen, may be used for dimensioning or for export to CAM. Here are the rules of association for phantoms:
All primitive structures have a common prefix consisting of 5 fields. This common structure is PRIM_NODE, a structure which is shown below.
This structure contains:
The following shows the definitions that are used to identify the various node types:
The OBJECT_NODE has a first_node pointer that gives access to all of the primitives within an object. Each primitive has a pointer to the next primitive (next_node) that is directly contained within the object. The next_node list terminates with a null pointer. The following illustrates a traversal of the primitives that linked directly to an object node:
The above function only identifies three primitive types. The remaining types are lumped together as "Other type". The structure of the polygon node is displayed below:
The following function lists the lines that are contained in polygons that are directly within the object. This function uses a first_node pointer in the POLYGON_NODE to locate the first primitive in a list of primitives within the polygon. These primitives (within the polygon) are linked via the next_node pointer and terminate with a null pointer. void display_lines_in_polygons( OBJECT_NODE *obj ) This function ignores all primitives other than polygons. Also, for each polygon, the function lists only lines, ignoring any arcs that might appear in the polygon. Each object in SilverScreen has a set of vertices. Each vertex in the set may be addressed by its vertex number. For an object that has n vertices, the range of vertex numbers is 1 through n. For a given object and a given vertex number, the function xyz_of_vertex returns a pointer to the xyz-coordinate associated with that vertex. The following will display the coordinates of all vertices in the object obj: OBJECT_NODE *obj; Each object also has a set of edges. Each edge is addressable with an edge number, and is associated with two vertex numbers. For a given object and a given edge number, the function vertex1_of_edge will return the vertex number of the first vertex, while vertex2_of_edge will return the vertex number of the second. The following displays the vertex numbers of all edges in obj:
For obj, the addresses of the coordinates of the vertices of edge i can be expressed as:
However, two additional functions, xyz1_of_edge and xyz2_of_edge, allow simpler expressions that are equivalent to those shown above:
The following can thus be used to display the coordinates of the edges of obj:
The structures of the point, line and round (circle/arc) nodes are shown below:
Each of these primitives uses references to the edge and vertex lists. LINE_NODE has an edge number that can be used to retrieve the endpoints of the line. POINT_NODE and ROUND_NODE have vertex numbers that can be used to retrieve the coordinate of a point. We give several examples. LINE_NODE contains an edge number edge. For LINE_NODE *p, the addresses of endpoints of p are given by the expressions:
The ROUND_NODE contains a vertex number center. For ROUND_NODE *r, the address of the center coordinate is given by:
In both cases above, note that r->parent is a pointer to the OBJECT_NODE that contains p. Note: The distributed sample program lister.c, which lists the components of a SilverScreen drawing, provides a guide to navigating the drawing data structure. Every primitive and entity may be referenced by means of a path. The path convention used for entities is nearly identical to the convention that is used in MS-DOS and Windows. Suppose that the object "door" is contained within a block "wall" which is contained within the block "room". Further suppose that "room" is contained within the root block. Then path to this object is
and the path to the block that contains "door" is
Given a path to a entity, the function get_bos will return a pointer to the entity.
Each primitive within an object has a unique identifying number. This id number, which appears in the PRIM_NODE structure, is automatically assigned when the primitive is created. A primitive within an object may be referenced by appending the id number to the object path. The path to the primitive with id 4 within the object "door" is
Each line node contains a reference to an edge. The edge, as noted earlier, contains a reference to two vertices. Suppose that the above primitive is a line. The first and second vertices of this line can be referenced by appending vertex number to the line path:
Given a path to a primitive, the pointer to the primitive can be obtained with the get_prim function. This function returns a pointer to the primitive while retrieving a pointer to the object that is the parent of the primitive. Note that the OBJECT_NODE pointer passed to get_prim is updated to point to the object node containing the primitive.
SilverScreen supports primitive groups and entity groups. Primitive groups are defined by a P-GROUP BEGIN command, a list of primitives that are to be in the group, and a P-GROUP END command. Here is an example:
Q-groups are defined using a similar command sequence. The following defines a group of objects:
Wildcards are one of the powerful tools available to the developer. Wildcard path names may be used to create Q-groups. They may also be used in commands. The wildcard characters are:
The "*" and "?" are used in the conventional manner. Here are several examples:
The "#" wildcard is used to identify, within a block, the entity with the highest numeric suffix for a given prefix. Suppose that the blocks \part1, \part5, and \part14 appeared in the root block. Then \part# would identify the block \part14. The "#" wildcard is often used in combination with the creation of entities. If the root block contained the blocks previously mentioned, then the command shown below will create a block \part15. Once this block has been created, it can be referenced by the wildcard path \part#.
The "!" wildcard will locate entities at any level of the drawing hierarchy. !knob* will match any entity in the drawing that has the prefix knob. Here it does not matter whether the entity is located at the root or six levels deep in the hierarchy. The "," wildcard allows the union of wildcard paths. Suppose that we want to identify all entities in the drawing hierarchy that had either the prefix "knob" or the prefix "latch". This can be done with the wildcard union !knob*,!latch*. Wildcards can be used to define groups. They can also be used directly in commands. The following illustrates both of these uses:
The TAG command permits information --- numeric values, strings, and 3D points --- to be attached to an entity. Each item of information is associated with a tag name. Variations of the TAG command permit tagged information to be attached, deleted and copied. The formats of the TAG command are displayed below: Add a tag to an entity:
Remove a specific tag from an entity:
Clear all tags attached to an entity:
Copy all tags from one entity to another:
In these commands:
Several examples of the TAG command:
Tag information for a specific tag name may retrieved program with the fetch_tag function. All tags associated with an entity may be retrieved with the get_tag function. Tags are automatically saved with the drawing when the drawing is saved. The attached tag values may be viewed with the extended version of the LIST command. E-Space, Base, Axis and Extents Entity structures contain E-space, base, axis, and extent information. The E-space is a private coordinate space for an entity, and is described by three fields within the entity structure: local_base, local_horz and local_vert. The local_base is the origin of the E-space, in world space coordinates. local_horz defines the direction of the positive x-axis of the space. local_vert defines the direction of positive y-axis of the space. The initial orientation of the E-space is dependent on the C-Space that is in effect when the entity is created. The E-SPACE command may be used to change this orientation. The base point is used for commands that involve scaling, rotation and shearing. The base point is stored in the center field of the BOS_NODE. This field receives a value when the entity is scaled, rotated or sheared. A value for this field may also be established manually by the FIX BASE command. The definition HAS_CENTER (bits1) indicates whether or not the base point has been established. Two points which define the axis of rotation are stored in the axis_top and axis_bottom fields of the BOS_NODE. These points are established when the entity is rotated axially. These may also be established manually by the FIX AXIS command. HAS_AXIS (bits1) indicates whether or not the axis has been established. The extents of an entity are the maximum and minimum x, y and z world space coordinates of the entity. This data is described by the high and low fields of the BOS_NODE. The maximum is held in the high field; the minimum is held in the low field. Entity exents may be retrieved through direct access to the BOS_NODE or through the use of the bos_extents function. Each entity has a visibility setting. This setting determines whether or not the entity will be displayed when the screen is refreshed. An entity is visible if the IS_VISIBLE bit of bits1 of the BOS_NODE is turned on. Otherwise the entity is not visible. There are two commands that control visibility -- ISOLATE and VISIBILITY. There are two functions, save_visibility and restore_visibility that can be used to save the current entity visiblities and later to restore all visibilities to the saved state. |
| Application-Oriented Commands There are a number of commands that are not available interactively. There are also a group of commands that require a more detailed description than is found in the SilverScreen Reference Manual. These commands are discussed in this section. Object-oriented 2D Boolean Commands The BOOLEAN commands permit Boolean operations between objects. The formats for these commands are described below: boolean trim objects object <path1> object <path2> The TRIM command expects to find one or more polygons in the object at <path1> and one or more polygons in the object at <path2>. The result of the trim operation is placed in the object at <path1>. The object in <path2> is unaltered: boolean difference objects object <path1> object <path2> The DIFFERENCE command is identical with the TRIM command except that the object in <path2> is purged at the completion of the operation: boolean intersection objects object <path1> object <path2> The INTERSECTION command expects a single polygon in the object at <path1> and one or more polygons in the object at <path2>. The result of the trim operation is placed in the object at <path1>. The object in <path2> is purged at the completion of the operation: Commands to Control Screen Refresh It is often desirable to perform commands without showing the results of the command on the screen. Several commands are provided for this purpose:
A situation that frequently occurs is the following: one wishes to first zoom the drawing and then to hide it. This is to be done without displaying the zooming operation on the screen. The following example illustrates:
This same result can also be accomplished with the SILENT keyword:
The record_visibility and reset_visibility functions are often used in combination with the REFRESH commands. Consider the following section:
The record_visibility function records the current visibility settings for the specified BOS (possibly root), while reset_visibility returns the BOS to their original settings. Between these two commands, the block \room4 is isolated. Since pick_entity only allows the selection of visible objects, only those objects in the block \room4 will candidates for selection. Other objects, although they can be seen on the screen, are, in fact, invisible. Note that this process takes place without changing the image that is displayed on the screen. Schemas and attributes may be used to associate non-graphical information with drawing entities. An attribute is a named numerical or text value. A schema is a named collection of attributes that may be attached to an entity. Schemas and their attributes are analogous to database records and their fields. Here are the commands to work with schemas:
Here are the commands that work with attributes:
Secondary definitions:
Schemas may be defined with fixed fields that may not be modified by the user, or with variable fields that need values assigned to them. If variable fields are present in the scheme, the ATTRIBUTE ASSIGN command will cause the Attribute editor to be invoked, so that the user may fill in values for the variable fields. The ATTRIBUTE ATTACH command causes any variable value fields to be assigned the value 0, and variable text fields to be assigned the empty string (""). The ATTRIBUTE QUERY command causes entities from a drawing to be selected on the basis of a logical condition, as represented by <formula>. <formula> is an expression expressing logical or relational conditions. For example:
The result of the ATTRIBUTE QUERY is textual information that is written to the specified destination. The information written is specified by the <attribute fields>, which is a comma separated list of attribute names or information fields. For example:
Information fields are provided to allow other information to be output as the result of a query:
For a more comprehensive discussion of schemas and attributes, see the SilverScreen Reference Manual. The PRINT Command The print command has been significantly expanded for Windows. The following discussion is an attempt to document all of the print command intricacies.
The print setup command presents the user with the default Windows print setup dialog. The user can use the dialog to change the current printer and (normally) the page orientation of the output.
The print orientation command is used to orient the printed output to be either vertical (portrait) or horizontal (landscape).
The print resolution command is used to control the quality of the image. On an HP LaserJet Series II printer, when the resolution is set to high, the Dots-Per-Inch (dpi) will be set to 300x300. When the resolution is medium, the dpi will be set to 150x150 and when the resolution is low the dpi will be set to 75x75. These numbers are presented to clarify the print resolution command and will change from device to device.
The print reset command does two things. First, it sets SilverEngines printer to the default Windows printer. Second, it sets all print options to their defaults (i.e. resolution high, orientation portrait). print {screen | area #,# #,#} [interactive] [copies #] [file] The print screen and print area commands are used to generate output onto the currently selected output device. Specifying the interactive keyword will cause SilverEngine to display a preview window with options to change the current printer, change the page setup, set the copies, and control the print destination. The file keyword means that output should go to a file and the user will be prompted for a file name. The copies keyword allows you to control the number of copies that will be generated on the output device. The number of copies must be greater than zero. Print screen requires no further parameters, but print area requires two pairs of numbers between zero and one. These pairs of numbers express screen percentages that used together define an area within the boundaries of the currently active window. The PAGE Command The page command is used to control the appearance of printed output on the output device.
The page setup command presents the user with SilverScreens page setup dialog. The user can then use the dialog to change the appearance of printed output. If the user chooses OK then all of the proper page commands will be issued. page justify {horizontal [left | center | right]} The page justify command aligns the bounding rectangle of the data being printed within the rectangle that is bounded by the user margins. page border The page border command controls the display of window borders (the bounding rectangle of each window) and the margin border (the rectangle formed by the user margins).
The page options command controls the status of several page options. The background option, when enabled, will draw the window backgrounds onto the printed output. The black-white option, when enabled, will draw all edges in black. The hide option, when enabled, will perform hide commands in the print preview.
The page template command assigns the print template that will be used during printing and previewing. To disable the use of a print template use the print template none form. To specify a particular template (say logo.pnt) use the print template file logo.pnt form.
The page margin command is used to control the user-defined margins. To set the user margins to the hardware margins of the currently selected output device use the page margin reset form. To set the left margin to (say) 4 inches use the page margin left 4 form. page size The page size command is used to control the size of the data being printed. The best-fit option will produce the largest possible print-out that maintains a correct aspect ratio. The width option allows you to specify the width of the printed output (the height will be automatically assigned). The height option allows you to specify the height of the printed output (the width will be automatically assigned). The scaled option allows you to control the ratio between the world-space of the current window and that of the printer. If you wanted to generate output where 1 measured inch is equivalent to 1 measured foot in the drawing then the following command would be used: page size scaled drawing 1 device 1".
The page reset command sets all options that affect the appearance of printed output to their defaults. It has the same affect as issuing the following sequence commands: page justify horizontal left vertical top In certain situations, you may wish to exercise finer control over the output device. There are several built-in functions provided for this purpose: printer_close, printer_open, printer_send . Legacy Printing Commands The following commands are associated with the original DOS version of SilverScreen, but are still supported under Windows. The Windows version of SilverScreen takes these commands and converts them into appropriate versions of the above PAGE and PRINT commands. The OPTIONS command:
The following HARDCOPY WIDTH commands allow line width to be controlled during printing:
In SilverScreen, annotation is primarily an interactive process, and as such, the full command set as implemented by the menu process is not available to the interactive file user. However, a subset of detailing commands may be used in C/C++ programs or script files. A summary of the syntax of this command subset follows: Commands for Setting the Detailing Environment
Commands for Inserting Details
Secondary Definitions
Commands for Reinserting Details Once a detail is inserted, the REINSERT command permits the user to adjust the detail interactively. This command permits the same formatting functions that are available in the interactive REINSERT command. The basic command is
This allows the user to adjust the single detail identified by <path>. A second version of this command,
allows the user to first select a detail, and then to adjust that detail. A final version
permits the user to modify as many details as he wishes. Detail modification, in this case, continues until the user signals that he is finished. All of the interactive drawing commands can be invoked with the IDRAW command. Here are the most common formats for the command: idraw arc {angles|chord|points} Since the user has the opportunity to escape from any of these commands, a program must be able to detect whether the user successfully completed the task. Here is one strategy for accomplishing this: create a new (empty) object; IDRAW; check to see if the object is empty. The code might appear similar to the following example: OBJECT_NODE *obj; CURSOR commands
These commands control the visibility of the world cursor. When the world cursor is enabled, there are five commands to control the type of cursor that is displayed:
ID RESET command
This command renumbers all primitive id's within a block or object. For each object, primitives are each given an integer id. This command will give these primitives an unbroken series of ids starting at 1. COPY commands The COPY command is used to copy drawing items to different parts of the drawing hierarchy.
This command places a copy of the object at <path1> in the block <path2>, giving it the name <new name>.
This command copies the single primitive at <path1> into the object at <path2>.
This command copies the single primitive at <path1> to the object at <path2>. E-SPACE commands There are several Geometry commands that are not available throughout the SilverScreen menu system. They are:
RELOCATE commands There is a variation of the RELOCATE command that allows an entity to be moved to the front or rear of its enclosing block. Since entities are displayed from front to rear, this command has the effect of altering the display sequence:
NOTE command The NOTE command displays a message on the help line and waits for a key press. The form of the command is:
The NOTE command is sometimes used as a simple debugging tool. Examples:
The WAIT command This is a variation of the NOTE command. It causes a message to be displayed on the screen for a fixed amount of time. The format is:
The TEXT-EDIT command The TEXT-EDIT command has a variation that invokes the text editor without the fancy programming features, that is without multiple windows, file-oriented text searches, DEBUG command support and SilverC help. The format is:
|
| Tools and Techniques This section of the manual concerns itself with tips, tools and techniques for building applications. Panel Menus are a simple means for constructing dialogs that request information from the user. For SilverC development, this is the primary method for interface with the user. For SilverEngine and SilverPlus, these menus offer a quick alternative to a the construction of a custom dialogs. There are three steps are required to use a panel menu:
There are 15 functions that define different types of panel input. Here is an overview of these functions:
Here is a short example illustrating the use of panels:
The initial values for machine_size, width, and machine_color will be used to initialize the panel. Values will be returned in these variables if pm_execute returns TRUE. The generic data sets represent a wide assortment of data that is used in SilverScreen. Each generic set has a corresponding constant that is defined in silver.h . The following is the list:
There are several ways that these sets can be used. The prompt_generic function displays a pop-up panel containing all names in a given data set. The user may then select one of these. This selection is then returned to the calling program. The following is an example: if ( prompt_generic("Select light source",buf,GN_LIGHT,"")
) The pm_generic function adds a generic item to a panel menu. The button associated with this item gives the user the opportunity to select an item from the set. The following is an example:
collect_generic is a function that assembles all items of a generic set into a list. This list may then be accessed through the get_generic function:
The generic data set is specified by a constant and an auxiliary string. In most cases, the auxiliary string is empty (as shown in the examples above). The sets that require a non-empty string are the following:
For GN_PATTERN and GN_LINE_STYLE, only "silver" should be used since this is the only library presently supported. GN_FILE requires the name of an ASCII text file containing space-delimited tokens. An example of such a file is the following (note that the end-of-line character counts as whitespace):
GN_FILE2 requires the name of an ASCII text file where each line is an element in the data set. Example:
GN_MODEL2 requires the name of the model library from which the model names are to be selected. SilverScreen Transformation Matrices In SilverScreen, a transformation matrix is a 4x4 array of doubles. One can view a transformation matrix as a function that maps points from one space to another space, typically representing some combination of the scaling, rotation and translation operations. For a point (x1,y1,z1), and a transformation matrix T, the mapping to (x2,y2,z2) is defined by the matrix multiplication
Transformation matrices may be multiplied together to produce composite transformations. For example, if the matrix T maps (x1,y1,z1) to (x2,y2,z2), and if the matrix S maps (x2,y2,z2) to (x3,y3,z3), then the matrix product T . S will map (x1,y1,z1) to (x3,y3,z3). Most commonly, matrices are multiplied to produce composite transformations. The chain of multiplications begins with the unity matrix, a matrix that has the value one in each diagonal element, and the value zero in all other elements. This matrix, if used to transform the point (x1,y1,z1), will map the point onto itself. Thus the unity matrix is, in effect, a null transformation. A typical operation performed with matrices is the following: A polygon with points p1, p2, p3 is to be scaled to one-half its size by scaling about the point p1. Here we assume p1 = (x1,y1,z1), p2 = (x2,y2,z2), and p3 = (x3,y3,z3).
The result of these operations is a composite transformation matrix that will scale all points in the polygon about the point p1. There are three types of transformation matrices that are explicitly supported by the SilverScreen API: translation, rotation, and scaling. Each of these functions performs two operations: First, a transformation matrix is created; second, the transformation matrix is multiplied into a composite matrix. The functions that perform these operations are:
The scaling and rotation functions are designed so that rotation and scaling can be performed independently on each axis. Here is the code that will produce the composite transformation matrix described in steps 1 through 7 above. double t[4][4]; In addition to the simple transformation functions described above, SilverC contains a number of specialized transformation tools. The function tm_cspace will produce a transformation matrix that maps points from world space to the current construction space. The following will transform a w-space point p to a c-space point q:
To transform a c-space point back to w-space, the function tm_inverse is used. The inverse function produces a matrix which maps in the opposite direction of the original matrix. The following will first get the w-space to c-space matrix tm. Then, tm_inverse is used to get the c-space to w-space matrix tm_inv. The final statement transforms the c-space point p1 to the w-space point p2.
For a more concrete example, consider the following problem. For a point p, we wish to locate a point q that is 2 units from p in the direction of the positive y-axis of c-space. Although this description, may sound complicated, this operation is, in fact, fairly common in geometric programming. The solution is:
The function w_to_c implicitly uses the w-space to c-space transformation matrix to transform a point from w-space to c-space. For a point p in w-space, the following produces the corresponding point q in c-space:
This is exactly equivalent to:
There is also an inverse function c_to_w that transforms a c-space point to w-space. The following function makes use of w_to_c and c_to_w to move the cursor on the xy-plane of c-space:
The function tm_to_2d will produce a transformation matrix that maps three non-collinear points to the xy-plane. For the points p1, p2, and p3, the tm_to_2d transformation will map p1 to the origin, p2 to a point on the positive x-axis, and p3 to a point on xy-plane with a positive y-coordinate. This function provides a powerful tool for solving 3D problems in 2D. Suppose, for example, that the points p1, p2, and p3 form a triangle somewhere in 3D space. To compute the area of this triangle, we can do the following:
SilverScreen is fully RGB-based. In all drawings, colors are stored as RGB values rather than color numbers. When a drawing is loaded, the RGB values are converted to color numbers that are appropriate to the video display. When a color is selected for a surface or a line, the user may express this color as an RGB value or as a color number. If a color number is selected, then this number is internally converted to an RGB value. The advantage of this approach is clear: SilverScreen drawings are independent of any color limitations imposed by the video device on which they were created. A surface, even on a 16-color system, may be given the RGB color of r13g120b93. On a 16-color system, this color may be interpreted as the color 3 (cyan). If the drawing is later displayed on an RGB video device, the color will be accurately portrayed as r13g120b93 . For video systems that do not have RGB display capability, SilverScreen uses a base palette of either 16 or 256 colors, dependent on the capabilities of the video device. Each color in SilverScreen is simultaneously maintained both as an RGB value and as a color from this palette. A special data type, RGB, defined in silver.h, is used to store this color information. The data type is an int, 32 bits in length. Eight bits are used to store the base color and 24 bits are used to store the RGB. There are several macros that are defined in silver.h that allow each of these values to be extracted:
The SilverScreen API also provides functions that convert color to RGB and RGB to color. color_to_rgb for a given base color, the function returns the RGB components of the color. rgb_to_color for an RGB, this function returns the base color appropriate for the current video device. The functions described in this section provide a means to creating an icon-based dialog. These functions provides a relatively easy way to create a dialogs that are functionally similar to a toolbars. Icons are supported with the icon, panel_icon, and pm_icon functions. The icon function displays the icons in the menu area, while the panel_icon function displays the icons at the center of the screen within a panel. The pm_icon function allows an icon item to be added to a panel menu, and invoked via a button. In this case, the icons appear in a pop-up panel in the center of the screen. Other related functions include icon2, panel_icon2, pm_icon2 , display_icon and clear_icons . The use of the icon functions is relatively straightforward. The greater effort is the preparatory design work. Icons are stored in what we shall call an icon drawing. Here are the characteristics of an icon drawing:
It is often attractive to have different background colors for different icons. By (8) above, it would seem that all icons would have the same background color. However, there is a way to work around this. Before creating any of the icons, create an object, say obj1. Since this object is the first entity in the drawing structure, it will be displayed first. Later, after all of the icons have been drawn, obj1 can be used to provide background color for individual icons. This is done by enabling fill and by placing colored polygons in obj1 that enclose the zoom extents of an icon. Since the polygon will be filled before the icon is drawn, the color of the polygon will be the background color for the icon. The automatic zooming described in (7) is sometimes a convenience and sometimes a burden. Let us consider the one of the troublesome aspects of scaling. Suppose that we wish to construct an icon drawing that has two icons, both of which are text. The first icon is to contain "YES" and the second "NO". We place the two lines in a drawing, and rename them so that "YES" is icon1 and "NO" is icon2. When these icons are displayed, we find that the letters of "NO" are larger than the letters of "YES". This is due to the automatic scaling that independently zooms each entity. In order to produce icons that are uniformly scaled, a scaling object must be introduced for each icon. The purpose of the scaling object is to establish the physical extents of the icon. In the above case, we would create two blocks, icon1 and icon2. Within these blocks, we would place two identically sized polygons, and then place the lines of text within the extents of these polygons. Once this is done, the scaling of the icon is dependent on the size of the scaling objects rather that the size of the text. To prevent the scaling objects from being displayed as part of the icon, their visibilities can be disabled. Alternatively, they can be given the color of the background. As a practical matter, it is often convenient to create a single icon block, icon1, which contains a scaling object. This block can then be matrix copied to produce as many icon blocks as desired. SilverScreen allows the use of custom menus. These menus, in appearance and in functionality, are very similar to the SilverScreen menus. The menus can be displayed using the built-in function menu. Using this function, a program can display a menu and receive the user's response. The construction of custom menus begins with a source file that defines the structure of the menus. This file is then compiled to produce a .CMF file. It is the .CMF file that is used by the menu function. Sample Custom Menu File
This is a simple menu consisting of three major menu selections (ceiling, floor, quit). The ceiling and floor selections have secondary menus, while the quit selection does not. The quoted strings are single line descriptors that appear at the top of the screen when the corresponding selection is highlighted. The numbers at the right are returned to the program if the user selects that item. Note that these numbers appear only at the leaf level of the menu tree. Let us assume that above source menu is stored in the file SAMPLE1. The file is compiled using the following SilverScreen command:
This will produce, in this example, a custom menu file SAMPLE1.CMF, which will be stored in the current directory. The CMF file may now be used by the menu function:
The menu command returns 0, 1, or a number corresponding to a menu selection. The return value 0 means that the user chose to enter Esc rather than select an item from the menu. The return value 1 means that the user pressed a function or control key. When this occurs, the key is made available in the predefined variable ich. The other numbers correspond to a successful menu selection by the user. .CMF files may be stored in executable libraries. This is particularly convenient when an application system has many such files. Structure of a Custom Menu File A custom menu file has the following format:
where:
The * menu item denotes that a menu separator is to appear at that location in the menu. SilverScreen has a set of control variables that control the run-time environment. These variables may be modified by the cv_set function. The current settings of control variables may be examined by the cv_get function. A number of these variables are read-only, that is, they may not be used as an argument to cv_set . The control variables are references using defined constants that appear in silver.h. The following is a description of the variables. Variables that are marked as read-only may not be used with cv_set :
Initial Setting at Start of Execution
The following is an example of the use of CV_ERRORS:
SilverScreen system variables are named storage objects that are global to the SilverScreen system. They are useful for communicating between programs. They may also be used to retrieve the results of certain SilverScreen commands (see below). Three types of system variables are allowed: value, text and XYZ. Value variables are used to hold a single floating point number (double). Text variables are used to hold a text string (char). XYZ variables are used to hold the location of a point in 3D space. In order to support XYZ variables, the data type struct _xyz is predefined by the C compiler. System variables may be accessed via the load_variable function or the sysvar functions. In SilverScreen, system variables are created, destroyed and assigned by using LANGUAGE VARIABLE commands:
To use system variables in a program, the variable must first be defined by using a VARIABLE ASSIGN command, or by loading a group of variables from disk using the VARIABLE LOAD command. A number of SilverScreen commands produce results that are assigned to various system variables. The commands that currently produce system variable results all belong in the GEOMETRY MEASURE family. The following table describes the variable created, the SilverScreen command that creates it and the data type of the variable created (the GEOMETRY prefix is not included in the command description):
Here is an example where the MEASURE command is used to measure the area of a polygon: double area; The VARIABLE V-EDIT command is a means for creating tab dialogues where large numbers of variables can be edited. The V-EDIT command is a close cousin to the panel menu family of functions (that is, pm_execute). However it differs from these functions in two respects:
V-EDIT is particularly useful in establishing a set of system parameters that are to be used during execution. The appearance and contents of the are specified in a V-EDIT source file. A sample V-EDIT file is shown below:
title specifies text that is to appear at the top of the screen during editing. input specifies the .VAR file that is to be used to initialize system variables. output specifies the .VAR file to which the system variables are to be written when the editing session concludes. Both input and output are optional. Starting on line 4, there is a line by line specification of the items that are to appear in the menu. The first character in each line identifies the type of information that is contained on the line:
Except for the line containing descriptive text, each line is associated with a system variable. The variable name appears immediately after the line code. The line code determines variable type and the value that will be assigned at the conclusion of the editing session:
Following the variable name is a string of display text. For menu lines, the last entry is the set of menu items. Initial values appear on the remaining lines. Further information about the V-EDIT command can be found in the SilverScreen Reference Manual. Multi-Language Applications: Tfiles Support for multi-language applications through the use of tfiles. Typically the developer maintains a set of messages, prompts and other text used to communicate with the user. This text may be stored in a single file, the tfile, for access by message number. To move to another language, only the text in the tfile needs to be translated, preserving message numbers. By accessing different tfiles, the application can move readily back and forth among languages. SilverScreen supports multiple language applications with a set of functions that allow the creation and use of external text files (tfiles). The tfile uses a text numbering system that associates each string of text with a number. By using the appropriate number, a line of text can be retrieved from the tfile. Here is a description of the functions that support files:
These functions provide the ability to change language at any time. This is consistent with SilverScreen's ability to change languages at a single keystroke. The tfile_make function permits developers to build their own tfiles from an input ASCII text file. The format of the input file is as follows:
The syntax for the text file is:
The following is an example of how to use tfiles. Assume that there are two input text files: english.txt and spanish.txt ; we will call the resultant tfiles english.tf and spanish.tf . To build the tfiles:
To start up in English:
To switch to Spanish:
To close out tfile usage:
Notice that there is no need to close a previous tfile before opening another -- that is done automatically by tfile_open . Keyboard and pointer events are handled in an event queue that is internal to SilverScreen. In a program, events are removed from the queue with the inchar function. The event may be a keystroke, a pointer movement, or a pointer button press. If the queue is empty when inchar is called, then the function waits until an event occurs. A second function, nextkey, may be used to view the event that is at the front of the queue without removing this event. If the queue is empty, nextkey does not wait for an event to occur, but instead, returns 0. The combination of nextkey and inchar can be used to clear the queue. First, nextkey checks to see if an event is in the queue. If so, then inchar is used to remove the event. Here is the code: while ( nextkey () ) Events handled in SilverScreen, both keys and pointer events, are defined in sskeys.h. This header file defines the function keys, the control keys, and the pointer button and motion events. Programs are able to monitor the location of the arrow and to determine its location. Here are the functions:
The events received from the pointing device are dependent on a pointer mode that can be set with pointer_mode. There are three modes: 0, 1 and 2. Mode 0 disables the pointer so that no pointer events occur. Mode 1 places the pointing device into key translation mode. When in this mode, pointer movement is translated to keyboard arrow movement, and certain button events are translated to keyboard keys. Mode 2 causes all pointer events to be returned. It is in mode 2 that pointer_locate and pointer_position functions are used. The following section illustrates the use of several of the pointer functions:
The pointer is placed in mode 2, located at position 20 of line 20, and made visible. The program then reads events with inchar, identifying Esc from the keyboard and the three mouse events. Executable libraries allow a consolidation of the various files that are included within an application. The following file types can be included in an executable library:
The notation "library>file" is used to refer to a file within a library. For example: iconlib>file1. Script files and executable programs can be executed from a library with a command of the form:
Custom menus can be loaded from a library with the menu function or with a command of the form:
Icon menus can be displayed from a library using the icon, icon2, and display_icon functions. Icons can also be used in panel_icon, panel_icon2, pm_icon , and pm_icon2 . Image files can be displayed from a library with a command of the form: The get_direct_pointer function is used to retrieve a direct pointer to the specified SilverScreen variable. Currently, the only variable supported is accessed by DP_LIGHT_LIST, which returns a pointer to the first LIGHT_NODE structure in a drawing (DP_LIGHT_LIST is defined in silver.h ; the LIGHT_NODE structure is defined in ss_nodes.h). See the get_direct_pointer in the Run-Time Library Reference. SilverScreen uses the Sentinel hardware lock. Each lock has a unique serial number that is recorded in the lock. The serial number can be accessed by the function get_version . Developers are often faced with protecting new versions and upgrades of their software. The purpose of this section is to suggest a method whereby a developer may use the serial number of the hardware lock to secure their software. The method involves computing a pass number based on the version number of the software and the serial number of the hardware lock. It assumes that the developer faithfully records the serial numbers of the packages on which their software is authorized to run. It also requires that the developer issue pass numbers with each release or update. These pass numbers are based on the serial number stored in the hardware lock. Consider the following function:
Based on a serial number and a version number, this function will generate a 5-digit pass number. For version 1, 2, ..., n, the function will generate a set of pass numbers that are seemingly unrelated to one another. The mechanism for protecting the software is simple: Before the software is sent to the user, the developer records the serial number of the user's hardware lock. Using this serial number, and the version number of their software, the developer computes a pass number that he gives to the user. When the user executes the developer's program, the program asks that the user enter a pass number. The program, using its access to the serial number, computes a pass number using the function shown above. If this number matches the number entered by the user, then access to the program is granted. This basic approach can be enhanced by storing correctly entered pass numbers on disk. In this way, the user would be required to enter the pass number only once. A b-tree database consists of two files: an index file and a data file. The index file is used to organize information that is stored in the data file. The index file contains a set of keys that are maintained in ascending sequence. Associated with each key is a record number. This record number identifies the record in the data file that is associated with the key. The keys in the index file can be accessed sequentially or randomly. For a given key, the associated record number can be used to retrieve the data file information that is related to that key. Two or more b-trees may be based on a single data file. This allows the information in the data file to be organized in several different ways. For a file containing employee information, one might construct one index to access employee information by employee number, while creating another index to access the information by employee name. Here is a summary of the b-tree functions: B-tree open, close and flush:
File creation functions:
Index file functions:
Data file functions:
B-trees are created by the bt_create_data and bt_create_tree functions. These functions create an empty data file and an empty index file respectively. When a data file is created, the record size must be specified. If text information is to be stored, then record size should be the length of the longest possible string. If structure information is stored, then record size should be the size of the structure (sizeof <structure name>). Before a b-tree can be accessed, it must be opened with bt_open. This function returns a b-tree handle. Index file functions use this handle to identify the index file, while data file functions use the handle to identify the data file. If two b-trees use a common data file, then either handle can be used to identify the data file. The purpose of this section is to describe a number of techniques that have proven themselves to be helpful in application development.
|
| Copyright Copyright 1994-1999 by Schroff Development Corporation, Shawnee-Mission, Kansas, United States of America. All rights reserved.
Disclaimer of All Warranties and Liability Schroff Development Corporation makes no warranties, either express or implied, with respect to this document or with respect to the hardware and software described in this document. Schroff Development Corporation does not guarantee, warrant or make any representation regarding the use of, or the results of the use of the information in terms of correctness, accuracy, reliability, or performance. Schroff Development Corporation assumes no liability for any direct, indirect, or consequential, special or exemplary damages, regardless of its having been advised of the possibility of such damage. |