OpenAlias

Fast Start with Plug-ins

The defaults for OpenAlias are set up such that it is not necessary to perform any operation before being able to use plug-ins.

Setting up OpenAlias

The OpenAlias environment has one requirement.

Plug-in search path

This colon-delimited path is used to search for plug-ins specified in the auto-load list and by the searching routines of the Plug-in Manager window. The Plug-in Manager window will be described in the next section.

By default this path is

.:$ALIAS_LOCATION/ODS/OpenAlias/plugins:$ALIAS_LOCATION/Conductors/ghostwriter

which causes $ALIAS_WORKENV (or the directory Alias was launched from if $ALIAS_WORKENV is not set) to be searched first, followed by the example plug-ins. Lastly, the Conductors directory is searched. Any number of directories can be listed with each searched in turn until a plug-in is found. Note that this default path is one of many that are searched for plug-ins as described in the "How OpenAlias Finds Files" section.

The Messages popup allows the selection of Full(verbose) or Brief messages. In Full or verbose message mode, detailed information will be written to the errlog file if there is an error during the loading or unloading of plug-ins.

The Plug-in Manager Window

The Plug-in Manager window is invoked from the Alias Utilities menu. This window displays all plug-ins currently in the Alias plug-in search paths. Refer to the next section "How OpenAlias Finds Files" to see the list of paths searched. The Plug-in Manager window is pictured below.

The Plug-in Manager window consists of 3 columns and a Browser button on the bottom. The columns list the plug-ins that are currently in the OpenAlias search paths and their load and auto-load status. A plug-in can be loaded by clicking on its associated Load/Unload check box. A check mark indicates that the plug-in has been loaded into Alias. Clicking on the check box of an already loaded plug-in will unload it. A plug-in can be made auto-loaded(loaded when Alias starts) by clicking on its associated check box. If any of the operations on plug-ins for this window fail, information will be sent to the Alias prompt-line and the errlog.

The Plug-in Browse button allows a user to select an arbitrary plug-in to be loaded.

Once selected, the plug-in is inserted into the Plug-in Manager list and is loaded. Auto-loading could be applied to this plug-in at this point. Plug-ins which are manually inserted by the Browse option take precedence over other plug-ins which may have the same name that are found in the search process.

The Plug-in Manager window searches the OpenAlias plug-in search paths every time it is opened. It is therefore sufficient, to close and open the window to have a new plug-in shown in the list.

The Plug-in Manager window writes out the auto-load list when it is closed.

How OpenAlias Finds Files

Below is the list of the directories that are searched for various files. If you are having problems with the loading of files, try checking the following load orderings.

Defining a Plug-in

A plug-in consists of several files. The only one that is required is the C++ source which defines the functionality of the plug-in. In addition, a plug-in may use any number of Scheme files to operate. The two most common Scheme files a plug-in may use are a pair of files describing each option box that the plug-in uses. One Scheme file describes the layout of the option box and the second provides commands which initialize the default values of variables.

Custom Icons For Plug-ins

Icons for plug-ins can be created using "xpaint". The icons will be loaded from the path specified by the icon (see the AlFunctionHandle::setIconPath() method for information), in the path specified by the environment variable $ALIAS_BITMAP_LOCATION or in the default Alias icon directory. You will need to create a medium sized icon (and save it with the extension `.M') and a small icon (and save it with the extension `.S'). Use the example icons in ODS/OpenAlias/plugins/medium and ODS/OpenAlias/plugins/small as a basis for new icons.

C++ Source File

These files are source code that defines the operation of the plug-in. They use the Alias API, the support functions, and define the UI functionality of the plug-in. The functionHandle encapsulates all of the operations on a UI menu button. A plug-in can define and control any number of menu buttons. A plug-in must define a entry function called plugin_init(). The exit function called plugin_exit() is optional.

plugin_init()

This function must be defined as:

extern "C" int plugin_init( const char* pluginDirPath )
It is executed immediately after the plug-in is loaded. pluginDirPath is a NULL terminated string which contains the absolute pathname to the directory that the plug-in was loaded from. The use of this path information is provided as a convenience to the plug-in. The path is intended to be passed to the initialization routines as an additional argument. This allows the plug-in to specify the exact location of its Scheme and icon files if they are not located in the default directories.

The developer uses this function to initialize the OpenAlias universe, and uses instances of the AlFunctionHandle class and AlMomentaryFunction or AlContinuousFunction classes (declared in the file scope to be available to the plugin_exit() function as well) to define the interface between Alias and the plug-in. On successful completion this function should return zero. If a non-zero value is returned from the plugin_init function, OpenAlias will assume that some error condition was encountered in initialization and will automatically unload the plug-in.

Note: we suggest doing the bare minimum in the plugin_init function. Allocate any user data that the plug-in will need but do not allocate any OpenAlias classes.

plugin_exit()

This function must be declared as:

extern "C" int plugin_exit( void )
It is called when the plug-in is removed or Alias is shut down. The programmer uses this function to do whatever is necessary to clean up the plug-in. This function should remove the plug-in from all menus using the deleteObject() method for each declared AlFunctionHandle and destroy any created AlFunctions using the deleteObject() method. On successful completion this function should return zero. Failing to remove all references may result in core dumps if they are accessed by Alias after the plug-in has been removed.

Static destructors and Exiting Alias

A change has been made in Alias Version 8.0 that affects the behavior of plug-ins when Alias exits. Plug-ins are no longer unloaded when Alias exits. This decreases the time that Alias takes to exit but results in static destructors of C++ classes not being called. The DSO is not explicity unloaded but is removed when Alias exits.

Static destructors will be called when a plug-in is unloaded manually. We suggest not performing operations within the static destructors of your classes. Note that plug_init() will still be called when Alias exits so any saving of data can be performed within that call.

First Scheme File

If the plug-in requires an option box the first Scheme file is used to define it. See the Scheme appendix to learn how this is done. All Alias option boxes are written in this format. For many examples of option box files, examine the .o.scm files that reside in subdirectories in the Alias install area.

Second Scheme File

If the plug-in requires an option box and the option box requires default values for its variables, these default values are set in this file which is invoked from plugin_init()

Important Plug-in Notes


summer% Alias -d dbx
debugging: /usr/aw/alias/bin/.Alias
dbx version 6.2 Mar 9 1996 15:23:28
Executable /usr/aw/alias/bin/.Alias
(dbx)

The environment variable AW_DEBUGGING must be set in order to use a debugger on the Alias binary. In Alias V8.0, the Alias script automatically sets this variable when it is invoked with the -d flag. Please read the API release notes for more information.

Creating Symbols and Strings

In order to pass information around in Scheme, it is necessary to define symbols as placeholders for values, and strings as names for those values. This is done through two primitives, ui-symbol and ui-string. These functions add elements to symbol tables inside of Alias, unlike the define primitive which adds a symbol to Scheme's symbol table. In places where the name of a symbol is desired (e.g. the label for a menu item), a search is done of the string symbol table for a string with the same symbol name as the given symbol. If one is found, the associated string is used. If not, the actual symbol name is used instead. So, for example:

(ui-symbol 'my_symbol 16)
The default value of the symbol will be 16. No ui-string is associated with this symbol. Therefore, the text "my_symbol" will appear whenever the name of this symbol is displayed.

Example 2:
(ui-string 'my_symbol "Number of Cows")
(ui-symbol 'my_symbol 16)
In this case a ui-string is defined with the same symbol name. When the name of the symbol "my_symbol" is required, a search is done for a ui-string with the same name. Here one is found, and the text "Number of Cows" will be used as the name of this symbol.

Creating an Option Box

Option boxes are created with a call to the ui-editor primitive. There are several arguments that apply to option boxes in general. The remaining arguments specify the widgets (editor tools) that make up the option box.

General Option Box Attributes

The following attributes describe the general behavior of an option box.

Example: (list 'title "View Frame Options")

Example: (list 'symbols 'nothing.intval 'nothing.doubval 'nothing.boolean )

Example:

Scheme file:
(ui-editor 'control.options
(list 'symbols 'control.pos_x)

(list 'init_option_function "control.init_func" )
(list 'title "Control Options")

(ui-double-widget 'control.pos_x
(list 'range -10.0 10.0)
(list 'precision "%f4.6")
)
)
)

Scheme init file:
(ui-symbol 'control.pos_x 0.0)
(ui-string 'control.pos_x "X")

Plug-in:
static void option_box_init_func( void )
{
AlSetDouble( "control.pos_x", 45 );
}

AlMomentaryFunction function;
AlFunctionHandle handle;

extern "C"
int plugin_init( const char* dirName )
{
AlUniverse::initialize();
function.create( "control.init_func", option_box_init_func );
// other code goes here
}

Note: Allocating memory in the init_option_function will result in memory leaks if the Exit button is selected. There is no corresponding exit_option_function where allocated memory can be released.

This function follows the same programming principles as the example in the previous bullet except that 3 functions will be needed.

Option Box Widgets

An option box can specify any number of ui-widgets, a set of editor tools like sliders, ticks, and buttons that can be used to set ui-symbols.

Radio and popup widgets are collectively called selector widgets. The order of the elements of the widget is unimportant with the exceptions that the variable is the first item and the choices will appear in the order specified. The following apply to both popup widgets and radio widgets. The columns property only applies to ui-radio-widget. It is ignored if specified in a popup widget.

  1. A simple radio widget
; Define the label strings.
(ui-string 'title_symbol_1 "First Choice")
(ui-string 'title_symbol_2 "Second Choice")
(ui-string 'title_symbol_3 "Third Choice")

(ui-radio-widget 'variable
(ui-choice 'title_symbol_1 'VALUE1)
(ui-choice 'title_symbol_2 'VALUE2)
(ui-choice 'title_symbol_3 'VALUE3)
)

  1. A simple popup widget
(ui-popup-widget 'variable
(ui-choice 'title_symbol_1 'VALUE1)
(ui-choice 'title_symbol_2 'VALUE2)
(ui-choice 'title_symbol_3 'VALUE3)
)

  1. Slider widgets allow the entry of data either by keyboard or with the slider. Below is a double slider.
(ui-string 'ao_set_device_offset "Offset")

(list 'symbols 'ao_set_device_offset )

(ui-double-widget 'ao_set_device_offset
list 'precision "%f6.3")
(list 'slider_range 1 10)
)

  1. A simple tick widget.
(list 'symbols 'nothing.boolean )

(ui-tick-widget 'nothing.boolean)

  1. Tickleft/right
Left:
(list 'symbols 'mo_bevel_front_cap)
(ui-tick-left-widget 'mo_bevel_front_cap)
Right:
(list 'symbols 'mo_bevel_front_cap)
(ui-tick-right-widget 'mo_bevel_back_cap)
If there is a whole group with a tick-left at the end,use the regular ui-tick-widget for the last one,otherwise there will be a hole on the right.

Rebuilding Selectors

If a rebuild is desired when a change of value occurs we add the rebuild property.

(ui-radio-widget 'variable
(list 'rebuild)
(ui-choice 'title_symbol_1 'VALUE1)
(ui-choice 'title_symbol_2 'VALUE2)
(ui-choice 'title_symbol_3 'VALUE3)
)

Selectively Enabling Selectors

Sometimes the selector should only be displayed under certain conditions.

The enabled property is used to specify this condition. The expression is built from the relational primitives ui-eq (equal), ui-ne (not equal), ui-lt (less than), ui-le (less than or equal), ui-gt (greater than), ui-ge (greater than or equal). The relational primitives can be combined using the logical primitives ui-and, ui-or, and ui-not.

(ui-radio-widget 'variable
(list 'enabled (ui-eq 'other_variable 'SOME_VALUE))
(list 'rebuild)
(ui-choice 'title_symbol_1 'VALUE1)
(ui-choice 'title_symbol_2 'VALUE2)
(ui-choice 'title_symbol_3 'VALUE3)
)

Changing Number of Columns

The default for radio widgets is two columns. To specify the number of columns use the columns property. The value range is 1, 2 or 3.

(ui-radio-widget 'variable
(list 'columns 3)
(list 'enabled (ui-eq 'other_variable 'SOME_VALUE))
(list 'rebuild)
(ui-choice 'title_symbol_1 'VALUE1)
(ui-choice 'title_symbol_2 'VALUE2)
(ui-choice 'title_symbol_3 'VALUE3)
)

Making Assignments to Variables

When a choice is selected you may assign a value to another variable. For example in the primitives option box the number of caps is set when cylinders or cones are specified.

(ui-radio-widget 'mo_prim_type
(list 'rebuild #t)
(ui-choice 'prim.type.cube 'MO_CUBE)
(ui-choice 'prim.type.plane 'MO_PLANE)
(ui-choice 'prim.type.circle 'MO_CIRCLE)
(ui-choice 'prim.type.cylinder 'MO_CYLINDER
(list 'assign 'mo_prim_caps 2)
)
(ui-choice 'prim.type.cone 'MO_CONE
(list 'assign 'mo_prim_caps 1)
)
(ui-choice 'prim.type.sphere 'MO_SPHERE)
)
These assignments may be made conditionally. If for example the number of caps for a cone should be set to one only if it was two then we could specify this as

(ui-choice 'prim.type.cone 'MO_CONE
(list 'assign (ui-eq 'mo_prim_caps 2) 'mo_prim_caps 1)
)
This way if it was set to zero then it wouldn't change.

Additional Widgets

  1. Separator widget
(ui-separator-widget)
Note that if the ui-radio-widget has an "enabled" bit to it, the separator widget has to have the same.

A Complete List of Widgets

  1. Selection Widgets

  1. Numbers

  1. Triples

  1. Miscellaneous

  1. Widget Properties

An Example

The following are the scheme files of the tree.plugin in the supplied examples. This code defines the option box used by the tree growing code. As mentioned above, the default values for these widgets are set from a separate file, invoked in the plug-in's initialization function. That file is also used to define the string names for the widgets. That way, these extra Scheme statements do not need to be reread each time the option box file is invoked. The file that defines the default values and the strings is called tree_init.scm:

tree_init.scm:

(ui-symbol 'seed 0)
(ui-string 'seed "Seed")

(ui-symbol 'max_branch 15)
(ui-string 'max_branch "Max Branch Limit");

(ui-symbol 'bend 0.2)
(ui-string 'bend "Bend")

(ui-symbol 'fork_angle 30.0)
(ui-string 'fork_angle "Fork Angle (deg)")

(ui-symbol 'branch_frequency 50.0)
(ui-string 'branch_frequency "Branch Frequency %")

(ui-symbol 'gravity -0.1)
(ui-string 'gravity "Gravity")

(ui-symbol 'branch_length 5.0)
(ui-string 'branch_length "Grow Length")

(ui-symbol 'trunk_taper 95.0 )
(ui-string 'trunk_taper "Trunk Taper %")

(ui-symbol 'min_branch_size 0.025 )
(ui-string 'min_branch_size "Minimum Branch Size")

(ui-symbol 'twist 45.0 )
(ui-string 'twist "Twist Angle (deg)")

(ui-symbol 'leaf.choice 0)
(ui-string 'leaf.choice "Type of Leaves")

(ui-string 'leaf_none "None")
(ui-string 'leaf_oak "Oak")
(ui-string 'leaf_maple "Maple")
(ui-string 'leaf_pine "Pine")

The other file is called tree.scm and contains the actual definition of the option box:

tree.scm:

(ui-editor 'tree.options

(list 'title "Fractal Tree Options")
(list 'symbols 'seed 'bend 'fork_angle 'branch_frequency 'gravity
'branch_length 'trunk_taper 'min_branch_size 'twist
'leaf.choice 'max_branch )

(ui-integer-widget 'seed
(list 'range 0 65535)
)

(ui-integer-widget 'max_branch
(list 'range 1 100)
)

(ui-double-widget 'bend
(list 'precision "%f6.4")
(list 'range -1.0 1.0)
)

(ui-double-widget 'fork_angle
(list 'precision "%f6.1")
(list 'range 0.0 90.0)
)

(ui-double-widget 'branch_frequency
(list 'precision "%f6.1")
(list 'range 0.0 100.0)
)

(ui-double-widget 'gravity
(list 'precision "%f6.4")
(list 'range -1.0 1.0)
)

(ui-double-widget 'branch_length
(list 'precision "%f6.4")
(list 'range 0.0 10.0)
)

(ui-double-widget 'trunk_taper
(list 'precision "%f6.1")
(list 'range 0.0 100.0)
)

(ui-double-widget 'min_branch_size
(list 'precision "%f6.4")
(list 'range 0.0001 1.0)
)

(ui-double-widget 'twist
(list 'precision "%f6.4")
(list 'range 0.0 90.0)
)

(list 'title "Leaf Options")
(ui-radio-widget 'leaf.choice
(ui-choice 'leaf_none 0)
(ui-choice 'leaf_oak 1)
(ui-choice 'leaf_maple 2)
(ui-choice 'leaf_pine 3)
)
)

Momentary Functions and Continuous Functions

There are two kinds of functions that can be invoked from the Alias menu: momentary functions and continuous functions.

Momentary Functions

A momentary function is essentially a single event: a function that takes no arguments and has no return value. It is simply a jump point in memory. Alias transfers control to this point when the menu item is invoked, the function executes, and control is returned to Alias. An example of a momentary function is `delete all'.

The simplest way to define a momentary function is through the AlMomentaryFunction class. Calling one of the create methods on an instance of that class will generate a new momentary function in Alias.

One can also define a momentary function in Scheme using the ui-function-define-momentary primitive. This primitive takes two arguments - the name of the momentary function to define, and a piece of executable Scheme code. This can be the name of another function or a lambda closure. Once the momentary function is defined, it can be referenced like any other and added to menus. For instance, to create a menu item that invokes the unix command `xcalc', one could add the following to Alias.scm:

(ui-function-define-momentary "InvokeXcalc"
(lambda () (unix-system "xcalc &")))
(ui-string "xcalc.str" "Invoke xcalc")
(ui-function "invoke_xcalc"
(list 'command "InvokeXCalc")
(list 'label_string 'xcalc.str)
)
(ui-menu-add-entry "al_goto" 'invoke_xcalc)
Note that the lambda expression attached to the momentary function uses the unix-system primitive, which executes its argument as a unix command.

Continuous Functions

A continuous function is more complicated than a momentary function. It is event driven: it must respond to user interaction through the mouse, keyboard, and user defined devices. As a result, continuous functions do not actually take over control of Alias when they execute. Rather, they define a context under which UI events are interpreted. Alias reads these events and transfers them to a group of event handlers defined by the continuous function. Thus a continuous function is a set of five callback functions: init, down, move, up and cleanup.

In addition, a continuous function is allowed to define pre-init and post-cleanup functions. The reason for these is that there are two ways to enter and leave the context of a continuous function. The function can be preempted temporarily by selecting some momentary function, or terminated more permanently by switching contexts to some other continuous function (or quitting Alias, of course). The pre-init and post-cleanup functions allow you to define actions that get invoked when Alias truly changes contexts and does not merely preempt your continuous function.

Init

"Init" is executed when the context of a continuous function is entered. This occurs when the function is first invoked, or after returning from a momentary function which pre-empted the function, or after reselecting this continuous function after completing some other continuous function.

Down

"Down" is called on every mouse down event. Use this function to detect the start of a click-drag type of operation.

Move

"Move" corresponds to the sequence of mouse movement events that occur between a mouse down and a mouse up. A move event will be generated for each significant mouse movement while a button is being held down. Further, "move" will be called in the case that the enter key is pressed on the keyboard. Therefore, it is in the move function that keyboard input should be detected.

Up

"Up" is called on mouse up events. Use this function to do things like commit transforms or create geometry corresponding to some sequence of mouse drags.

Cleanup

"Cleanup" is called when the context of this function is left to perform some other action. For example, if the user is in the context of your continuous plug-in, and invokes some other momentary function, the cleanup function will be called, followed by the momentary function, followed by the "init" function when Alias returns to the context of the original continuous function.

Attaching a Plug-in to a Menu

The first step in attaching plug-in functionality to a menu is to create an AlFunction object. The AlFunction class encapsulates information about what actions to perform when your plug-in is selected. It represents the `back end' of a menu item. In particular, a plug-in would create an AlMomentaryFunction or an AlContinuousFunction to describe its operation.

To actually define the menu item which will invoke that AlFunction, use the AlFunctionHandle class, which provides a C++ interface to Scheme.

The file AlFunctionHandle.h must be included by the plug-in to use AlFunctionHandle. AlFunction.h must be included to use either AlMomentaryFunction or AlContinuousFunction.

In the plugin_init() function of the plug-in the various methods of the AlFunctionHandle are used to define the menu item (or menu items) that will be added to OpenAlias, and the AlFunction classes are used to register the functions which make up the functionality of the plug-in. In the case of using Scheme instead of AlFunctionHandle, plugin_init() would at some point invoke a Scheme file that performs the necessary UI initialization.

AlFunctionHandle

Any instance of this class must be defined in the file scope so that it is available to the plugin_init() and plugin_exit() functions.

AlFunctionHandle::create()

Prototype:

statusCode AlFunctionHandle::create( const char * name, const char * command );
statusCode AlFunctionHandle::create( const char * name, AlFunction *func );
Description:

These methods are used to create the function handle and set some of its attributes. (It is also possible to use the constructor to create the function handle.)

Arguments:

AlFunctionHandle::setAttributeString

Prototype:

statusCode AlFunctionHandle::setAttributeString( const char * str );
Description:

This method sets the string which will appear on the attribute line below the prompt line when the plug-in is selected from the menu.

Arguments:

AlFunctionHandle::setOptionBox

Prototype:

statusCode AlFunctionHandle::setOptionBox( const char * schemeFileName, const char * editorName, const char* dirPrefix );
Description:

This method sets the option box for the plug-in. If the plug-in has no option box, this method need not be used. This method wil fail if the scheme file described by the name and prefix does not exist.

Arguments:

AlFunctionHandle::setIconPath

Prototype:

statusCode AlFunctionHandle::setIconPath( const char * iconPath );
Description:

This method sets the pathname to load the icon images from. If the path is not set, then the icon image will be loaded from the standard bitmap locations ($ALIAS_BITMAP_LOCATION or $ALIAS_LOCATION/bitmaps). Currently the icon path must contain two directories: `small' and `medium'. Each directory contains an image of the icon to be displayed. The small image must have the suffix `.S', and the medium sized image must have the suffix `.M'.

For example, if the function name is `myFunc', then the directory would be setup as:

..../small/myFunc.S
..../medium/myFunc.M
Arguments:

AlFunctionHandle::addToMenu and AlFunctionHandle::appendToMenu

Prototype:

statusCode AlFunctionHandle::addToMenu( const char * menuname );
statusCode AlFunctionHandle::appendToMenu(const char * menuname);
Description:

These methods add the plug-in to the menu. addToMenu() adds the plug-in to the bottom of the menu, while appendToMenu() will add it to the top of the menu.

Arguments:

Available Menus

Plug-ins can be attached to the following menus.

Table 1: Available menus

Menu Identifier

µ

_

_

_

_

_

_

_

_

_

__

_

_

_µ

µ

_µ

µ

µ_

µ_

µ_

µ_

µ_

µ_

µ_

µ_

µ_

µ_

µ

µ_

µ__µ

µ_µ

µ

_

_

()

AlFunctionHandle::removeFromMenu

Prototype:

statusCode AlFunctionHandle::removeFromMenu();
Description:

This method removes the function handle from the menu.

Return codes:

AlFunctionHandle::deleteObject

Prototype:

statusCode AlFunctionHandle::deleteObject();
Description:

This method deletes the function handle from the menu and completely invalidates it.

Return codes:

AlFunctionHandle::operator =

Prototype:

AlFunctionHandle& AlFunctionHandle::operator =( const AlFunctionHandle& f )
Description:

This defines the assignment operator for the AlFunctionHandle class.

Arguments:

AlFunctionHandle::operator!

Prototype:

int AlFunctionHandle::operator !() const
Description:

This method allows us to check the validity of a function handle.

ex.

if ( functionhandle ) ...

Examples

Momentary Plug-Ins

Below is an example of a plug-in which does a viewframe on all picked objects. It is a simple example of a momentary plug-in.

frame_init.scm

;; This file simply gives the defaults for the Scheme variables
;; used in the option box.
(ui-symbol "frame" 0)
(ui-string "frame" "Frame")

frame.scm

;; This file defines the option box
(ui-editor "frame.options"
(list 'symbols 'frame )

(list 'title "View Frame Options")

(ui-integer-widget "frame"
(list 'range 0 65535)
)

)

frame.c++

#include <AlUniverse.h>
#include <AlViewFrame.h>
#include <AlPickList.h>
#include <AlObject.h>

#include <AlLiveData.h>
#include <AlFunction.h>
#include <AlFunctionHandle.h>
#include <AlIterator.h>

#include <strings.h>

extern char * makeAltPath(const char *dirName, const char *suffix);

// A simple iterator used to pass the frame number
// along when viewing an object.
class viewIterator: public AlIterator
{
public:
viewIterator( double frame = 0.0 )
: frameNum( frame ) {};
virtual ~viewIterator() {};

virtual int func( AlObject* );

private:
double frameNum;
};

// The iterator's one and only method. Does a viewframe
// on the passed in object using the frame number in the
// iterator object.
int viewIterator::func( AlObject* obj )
{
if ( obj == NULL )
return 0;

AlAnimatable* animitem;
AlCurve* curve;
AlSurface* surface;

AlObjectType type = obj->type();

if( animitem = obj->asAnimatablePtr() )
AlViewFrame::viewFrame( animitem, frameNum, AlViewFrame::kObjectAndBelow );
else if( curve = obj->asCurvePtr() )
AlViewFrame::viewFrame( curve, frameNum );
else if( surface = obj->asSurfacePtr() )
AlViewFrame::viewFrame( surface, frameNum );
else
AlPrintf( kPrompt, "Sorry, %s is not a viewable object", obj->name() );
; // a non viewable object
return 0;
}

// The actual plugin function.
void my_view()
{
int frameNum;

// Get the frame number from the option box.
if( sSuccess == AlGetInteger( "frame", frameNum ) )
{
// Print the number to the promptline.
AlPrintf( kPrompt, "Viewing frame %d.", frameNum );

// Instantiate an iterator and apply it to all picked
// objects.
int rc;
viewIterator* view = new viewIterator( frameNum );
if ( sSuccess != AlPickList::applyIteratorToItems( view, rc ) )
AlPrintf( kPrompt, "Iterator failed." );
if ( rc != 0 )
AlPrintf( kPrompt, "Return code is %d.", rc );

AlPrintf( kPrompt, "Viewing complete." );
}
}

// This handle may have to be global if you wish to remove the
// plugin from the menu using the h.destroy() method in the
// 'momentary_exit' function.
// The menu entry is automatically removed when Alias exits.
//
AlFunctionHandle h;
AlMomentaryFunction hFunc;

extern "C"
int plugin_init( const char *dirName )
//
// This routine initializes the plugins and attaches it to the menu.
// It returns 0 if there is no initialization error.
//
{
char *dirScm;

// Initialize the universe. This must be done by all
// plugins. If the universe is not initialized the plugin
// will fail.
AlUniverse::initialize( );

dirScm = makeAltPath(dirName,"scm");

// Invoke the scheme file which sets defaults for the scheme
// variables.
AlInvokeSchemeFile( "frame_init.scm", dirScm );

// Allocate a function handle. The first argument is the label on
// the menu and the second is the function to invoke when the
// menu item is selected.
hFunc.create( my_view );
h.create( "View Frame", &hFunc );

// Define the attribute string for the attribute line below
// the prompt line.
h.setAttributeString( "viewframe" );

// Read in the option box. The first argument is the
// option box in $ALIAS_WORKENV, and
// the second argument is the name of the option box given
// in the scheme file. The third argument is a directory
// path(possibly NULL) where to look for the scheme file.
// If a call to this method is omitted, there will be no option box.
if ( sSuccess != h.setOptionBox( "frame.scm", "frame.options", dirScm) ) {
AlPrintf(
kPrompt,
"Frame plug-in unable to find .scm file for option box"
);
return (1);
}


// Indicate which menu to add the plugin to. addToMenu()
// adds the plugin to the bottom of the menu, while
// appendToMenu() will add it to the top of the menu.
h.addToMenu( "mp_objtools" );

h.setIconPath( makeAltPath( dirName, NULL ) );

// Return a success code.
// Returning a non zero indicates an error.
// An error value ( a non-zero ) will be printed on the prompt
// line in Alias.
AlPrintf( kPrompt, "Frame attached to Palette 'Object Edit'");
return 0;
}

extern "C"
int plugin_exit( void )
{
// Remove the plugin from the menu and free the FunctionHandle.
// Note that h.destroy() implicitly calls h.removeFromMenu()
h.deleteObject();
hFunc.deleteObject();
return 0;
}


Continuous Plug-Ins

This example is a skeleton for continuous plug-ins. It echoes all user interaction to stdout.

cont.c++


// cont.plugin
//
// This file implements a simple continuous function plugin, a plugin
// that gets events from Alias and can interact with the user. It can
// be used as a skeleton from which to construct other, more complicated
// continuous functions if desired.
//

#include <AlLiveData.h>
#include <AlFunction.h>
#include <AlFunctionHandle.h>

#include <AlUniverse.h>
#include <AlDagNode.h>
#include <AlPickList.h>
#include <AlPickable.h>
#include <AlWindow.h>

char inbuf[ 256 ];
char text_buf[ 100 ];
const char * my_prompt = "Enter some text: %s";

extern char * makeAltPath(const char *dirName, const char *suffix);

void go_button_pressed( void )
{
AlPrintf( kStdout, "Go button pressed!\n" );
AlContinuousFunction::createGoButton( go_button_pressed );
}

static void init_func( void ) {
AlPrintf( kStdout, "Now entering continuous plugin.\n" );
AlContinuousFunction::createGoButton( go_button_pressed );
}

static void down_func( int input, Screencoord x, Screencoord y )
{
int button;
double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1;
AlWindow * w;

switch( AlContinuousFunction::translateInput( input, button ) ) {
case kInputButton:
w = AlUniverse::currentWindow();
w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez );
AlPrintf( kStdout, "Mousedown at %d,%d [%lf,%lf,%lf %lf,%lf,%lf]. Button %d.\n",
x,y, dx,dy,dz, ex,ey,ez, button );
delete w;
break;
}
}

static void move_func( int input, Screencoord x, Screencoord y )
{
int button;
double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1;
AlWindow * w;

switch( AlContinuousFunction::translateInput( input, button ) ) {
case kInputButton:
w = AlUniverse::currentWindow();
w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez );
AlPrintf( kStdout, "Mousemove at %d,%d [%lf,%lf,%lf %lf,%lf,%lf]. Button %d.\n",
x,y, dx,dy,dz, ex,ey,ez, button );
delete w;
break;
case kInputKeyboard:
sscanf( inbuf, "%s", text_buf );
AlPrintf( kStdout, "Text input: %s [%s]\n", text_buf, inbuf );
break;
}
}

static void up_func( int input, Screencoord x, Screencoord y )
{
int button;
double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1;
AlWindow * w;

switch( AlContinuousFunction::translateInput( input, button ) ) {
case kInputButton:
w = AlUniverse::currentWindow();
w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez );
AlPrintf( kStdout, "Mouseup at %d,%d [%lf,%lf,%lf %lf,%lf,%lf]. Button %d.\n",
x,y, dx,dy,dz, ex,ey,ez, button );
delete w;
break;
}
}

static void cleanup_func() {
AlPrintf( kStdout, "Now leaving continuous plugin.\n" );
AlContinuousFunction::clearGoButton( TRUE );
}

AlFunctionHandle h;
AlContinuousFunction hFunc;

extern "C"
int plugin_init( void )
{
AlUniverse::initialize();

hFunc.create( "Continuous", init_func, down_func, move_func,
up_func, cleanup_func, TRUE );
hFunc.setPrompt( my_prompt, inbuf, kFilterNone );
h.create( "Cont Test", &hFunc );
h.setAttributeString( "cont" );
h.setIconPath( makeAltPath( dirName, NULL ) );
h.addToMenu( "mp_objtools" );

AlPrintf( kPrompt, "Continuous example installed on Palette 'Object Edit.");
return 0;
}

extern "C"
int plugin_exit( void )
{
h.removeFromMenu();
h.deleteObject();
hFunc.deleteObject();

return 0;
}

Command History Plug-Ins

Command history plug-ins are very complex, and it is advisable not to attempt creating one until a firm understanding of momentary and continuous plug-ins has been developed.

As mentioned earlier, command history plug-ins are not attached to a menu, but rather they are invoked when geometry changes.

See the documentation on AlCommand, AlUserCommand, and AlNotifyDagNode, as well as the examples constrainCV.c++ and polyhist.c++.

It is important to note that when modifying geometry the doUpdates() method of the geometry should be called with FALSE, and never called with TRUE. This is necessary since the command is being called from within the message system, and updates generate messages. If updates are performed during a command then unnecessary messages will be generated, and it is possible that a loop could be created where the command is responding to a message it generated.

Examples Explained

Please see the Readme files for information on the examples.

OpenAlias/Plugins

In this directory you will find precompiled versions of some of the files in the examples directory. We only precompile plug-ins that have useful functionality as opposed to programming examples.

Common/include

All the include files necessary to build OpenAlias plug-ins are located in this directory.

Common/examples

Some of the example source code is common between OpenAlias and OpenModel. This source code is located in this directory and includes the C API. Note that you will need to have the compiler flag

-I$(ALIAS_LOCATION)/ODS/Common/examples
in your compile flags (CFLAGS) in your Makefile if you use the AlPrint functions in your programs.





aliasdocs@aw.sgi.com
Copyright © 1996, Alias|Wavefront, a Silicon Graphics Company. All rights reserved.